Skip to content

Commit 77f2b81

Browse files
committed
Set SOCK_CLOEXEC for debugger sockets
It's possible to configure HHVM access logs to be sent to a subprocess instead of a file, like so: ``` Log { Access { * { File = |/usr/bin/some_processor.sh | tee -a /tmp/hhvm-access.log } } } ``` Under the hood, this is backed by a `popen(3)` syscall in `ClassicWriter`, which ultimately creates a pipe, forks and invokes a shell. If HHVM is running with the debugger enabled (`hhvm.debugger.vs_debug_enable=1`), this subprocess also ends up inheriting the file descriptor backing the listening socket of the debugger. If a connected debugger client then disconnects, the debug server will then restart and try to open a new socket, but fail because the FD remains open in the child process. So, set `SOCK_CLOEXEC` on these sockets so that they get closed in child processes.
1 parent 31e40e9 commit 77f2b81

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

hphp/runtime/ext/vsdebug/socket_transport.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <pwd.h>
2525
#include <grp.h>
26+
#include <sys/socket.h>
2627

2728
namespace HPHP {
2829
namespace VSDEBUG {
@@ -302,7 +303,7 @@ bool SocketTransport::bindAndListenDomain(std::vector<int>& socketFds) {
302303
struct sockaddr_un addr;
303304
std::string socketPath = m_domainSocketPath;
304305

305-
int sockFd = socket(AF_UNIX, SOCK_STREAM, 0);
306+
int sockFd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
306307
if (sockFd < 0) {
307308
VSDebugLogger::Log(
308309
VSDebugLogger::LogLevelError,
@@ -360,7 +361,7 @@ bool SocketTransport::bindAndListenTCP(
360361
std::vector<int>& socketFds
361362
) {
362363
int fd = socket(address->ai_family,
363-
address->ai_socktype,
364+
address->ai_socktype | SOCK_CLOEXEC,
364365
address->ai_protocol);
365366

366367
if (fd < 0) {

0 commit comments

Comments
 (0)