Skip to content

Commit

Permalink
Fix debugger connection issue on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Nov 29, 2024
1 parent 0216431 commit f64a4c4
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/js/internal/debugger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerWebSocket, Socket, WebSocketHandler, Server as WebSocketServer } from "bun";
import type { Socket, ServerWebSocket, WebSocketHandler, Server as WebSocketServer } from "bun";
const enum FramerState {
WaitingForLength,
WaitingForMessage,
Expand Down Expand Up @@ -411,8 +411,43 @@ async function connectToUnixServer(
send: (message: string) => void,
close: () => void,
) {
// Windows uses TCP.
// POSIX uses Unix sockets.
//
// We use TCP on Windows because VSCode/Node doesn't seem to support Unix sockets very well.
//
// Unix sockets are preferred because there's less of a risk of conflicting
// with other tools or a port already being used + sometimes machines don't
// allow binding to TCP ports.
let connectionOptions;
if (unix.startsWith("unix:")) {
unix = unescapeUnixSocketUrl(unix);
if (unix.startsWith("unix:")) {
unix = unix.substring("unix:".length);
}
connectionOptions = { unix };
} else if (unix.startsWith("tcp:")) {
try {
const { hostname, port } = new URL(unix);
connectionOptions = {
hostname,
port: Number(port),
};
} catch (error) {
exit("Invalid tcp: URL:" + unix);
return;
}
} else if (unix.startsWith("/")) {
connectionOptions = { unix };
} else if (unix.startsWith("fd:")) {
connectionOptions = { fd: Number(unix.substring("fd:".length)) };
} else {
$debug("Invalid inspector URL:" + unix);
return;
}

const socket = await Bun.connect<{ framer: SocketFramer; backend: Backend }>({
unix,
...connectionOptions,
socket: {
open: socket => {
const framer = new SocketFramer((message: string | string[]) => {
Expand Down

0 comments on commit f64a4c4

Please sign in to comment.