Skip to content

Commit 0a42245

Browse files
committed
vsdebug: Fix double-closing listener FDs
While working on D88186184, I noticed that we were closing the listener FDs for the vsdebug server in both `waitForConnection` and `listenForClientConnection`. It does not seem to be causing issues in local testing but it could be a problem if the FD gets reused in a different thread in the meantime. `waitForConnection` is only called at the end of `listenForClientConnection` so closing the FDs only at the end of `listenForClientConnection` should be fine.
1 parent 0e594e0 commit 0a42245

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

hphp/runtime/ext/vsdebug/socket_transport.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "hphp/util/configs/debugger.h"
2222
#include "hphp/util/user-info.h"
2323

24+
#include <algorithm>
25+
2426
#include <pwd.h>
2527
#include <grp.h>
2628
#include <sys/socket.h>
@@ -160,9 +162,7 @@ void SocketTransport::listenForClientConnection() {
160162
freeaddrinfo(ai);
161163
}
162164

163-
for (auto it = socketFds.begin(); it != socketFds.end(); it++) {
164-
close(*it);
165-
}
165+
std::for_each(socketFds.begin(), socketFds.end(), close);
166166

167167
close(abortFd);
168168
m_abortPipeFd[0] = -1;
@@ -575,10 +575,6 @@ void SocketTransport::waitForConnection(
575575
if (fds != nullptr) {
576576
free(fds);
577577
}
578-
579-
for (const int fd : socketFds) {
580-
close(fd);
581-
}
582578
};
583579

584580
// fds[0] will contain the read end of our "abort" pipe. Another thread will

0 commit comments

Comments
 (0)