Skip to content
Browse files
HHVM Debugger: Send a custom DAP message when a connection is refused
Summary: When refusing a debugger client due to another client already being connected, send a custom protocol message clients can interpret, rather than just an OutputEvent.

Reviewed By: mostafaeweda

Differential Revision: D8899412

fbshipit-source-id: 1ad3d911b27a0fe442530ea0e5b53d3e130889e9
  • Loading branch information
ebluestein authored and hhvm-bot committed Jul 20, 2018
1 parent 0ed4aee commit 67e26a1ef3010a892b2530eacc3aa9a6563d6aa8
Showing with 11 additions and 1 deletion.
  1. +8 −1 hphp/runtime/ext/vsdebug/socket_transport.cpp
  2. +3 −0 hphp/runtime/ext/vsdebug/transport.h
@@ -254,7 +254,7 @@ void SocketTransport::rejectClientWithMsg(int newFd, int abortFd) {

folly::dynamic rejectMsg = folly::dynamic::object;
rejectMsg["category"] = OutputLevelError;
rejectMsg["output"] = "Could not attach to HHVM: another debugger "
rejectMsg["output"] = "Failed to attach to HHVM: another debugger "
"client is already attached!";

folly::dynamic response = folly::dynamic::object;
@@ -267,6 +267,13 @@ void SocketTransport::rejectClientWithMsg(int newFd, int abortFd) {
const char* output = serialized.c_str();
write(newFd, output, strlen(output) + 1);

// Send a custom refused event that clients can detect.
folly::dynamic refusedEvent = folly::dynamic::object;
refusedEvent["event"] = EventTypeConnectionRefused;
refusedEvent["type"] = MessageTypeEvent;
const char* refusedEventOutput = folly::toJson(refusedEvent).c_str();
write(newFd, refusedEventOutput, strlen(refusedEventOutput) + 1);

// Perform an orderly shutdown of the socket so that the message is actually
// sent and received. This requires us to shutdown the write end of the socket
// and then drain the receive buffer before closing the socket. If abortFd
@@ -75,6 +75,9 @@ struct DebugTransport {
// VS Code protocol event types
static constexpr char* EventTypeOutput = "output";

// Custom event types.
static constexpr char* EventTypeConnectionRefused = "hhvmConnectionRefused";

// Message output levels to be displayed in the debugger console.
// NOTE: the protocol explicitly defines:
// "console", "stdout", "stderr", "telemetry", with "console" being the

0 comments on commit 67e26a1

Please sign in to comment.