Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for windows debug support #14048

Merged
merged 19 commits into from
Sep 21, 2024
Merged

fix for windows debug support #14048

merged 19 commits into from
Sep 21, 2024

Conversation

snoglobe
Copy link
Contributor

@snoglobe snoglobe commented Sep 19, 2024

What does this PR do?

this fixes #8851, which pertains to the bun debugger not working on windows.

for windows platform, we now use websockets to communicate to the debugger and inspector. on unix platforms, we keep the existing unix sockets implementation.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

tested it by debugging programs under vscode in windows

@snoglobe
Copy link
Contributor Author

note: failed builds are due to buildkite

import { Location, SourceMap } from "./sourcemap";
import { createServer, AddressInfo } from "node:net";

export function getAvailablePort(): number {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wait for the callback to be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works fine without waiting for callback

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does node gurantee that the address will always be set before the listen callback is invoked?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server.address() returns null before the 'listening' event has been emitted or after calling server.close().

@@ -9,7 +9,7 @@ buildSync({
entryPoints: ["src/extension.ts", "src/web-extension.ts"],
outdir: "dist",
bundle: true,
external: ["vscode"],
external: ["vscode", "ws"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

@snoglobe
Copy link
Contributor Author

snoglobe commented Sep 20, 2024 via email

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Sep 20, 2024 via email

@snoglobe
Copy link
Contributor Author

What happens when you build the installed extension and the ws package isn’t installed?

errors w/ the bundler unable to resolve ws

@Jarred-Sumner
Copy link
Collaborator

errors w/ the bundler unable to resolve ws

did you run bun install (or npm install)?

@@ -73,7 +83,7 @@ class Debugger {
#listen(): void {
const { protocol, hostname, port, pathname } = this.#url;

if (protocol === "ws:" || protocol === "ws+tcp:") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're allowing wss, where is the TLS configuration specified?

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not mergeable until:

  1. the listen() callback is addressed (it will be randomly flaky, in it's current version even if it appears to work sometimes when you run it locally)
  2. The "ws" module should not be external. We bundle the VSCode extension instead of expecting a node_modules folder to be present (it won't be, except for development)

Separately, the "wss" validation is a little confusing unless the idea is you have a reverse proxy between Bun.serve() and the websocket connection? This is uncommon, as people usually don't proxy websockets but not impossible I suppose.

@@ -321,6 +331,18 @@ function reset(): string {
return "";
}

function notifyWebSocket(url: string): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's a whole websocket server for this? We can just make a TCP connection.

@Jarred-Sumner
Copy link
Collaborator

I want to get the Bun changes into the release, so going to merge that separately from this PR since the extension can be updated separately after

@snoglobe
Copy link
Contributor Author

Not mergeable until:

  1. the listen() callback is addressed (it will be randomly flaky, in it's current version even if it appears to work sometimes when you run it locally)
  2. The "ws" module should not be external. We bundle the VSCode extension instead of expecting a node_modules folder to be present (it won't be, except for development)

Separately, the "wss" validation is a little confusing unless the idea is you have a reverse proxy between Bun.serve() and the websocket connection? This is uncommon, as people usually don't proxy websockets but not impossible I suppose.

will remove wss validation then; yeah not sure why i put it

@snoglobe
Copy link
Contributor Author

errors w/ the bundler unable to resolve ws

did you run bun install (or npm install)?

yes

@@ -2149,10 +2207,10 @@ function titleize(name: string): string {
}

function sourcePresentationHint(url?: string): DAP.Source["presentationHint"] {
if (!url || !url.startsWith("/")) {
if (!url || path.isAbsolute(url)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!path.isAbsolute


const query = stopOnEntry ? "break=1" : "wait=1";
processEnv["BUN_INSPECT"] = `${url}?${query}`;
processEnv["BUN_INSPECT_NOTIFY"] = `tcp://127.0.0.1:${signal.port}`; // 127.0.0.1 so it resolves correctly on windows
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
processEnv["BUN_INSPECT_NOTIFY"] = `tcp://127.0.0.1:${signal.port}`; // 127.0.0.1 so it resolves correctly on windows
processEnv["BUN_INSPECT_NOTIFY"] = signal.url

@Jarred-Sumner Jarred-Sumner merged commit 722e3fa into main Sep 21, 2024
8 of 24 checks passed
@Jarred-Sumner Jarred-Sumner deleted the debugger_ws branch September 21, 2024 07:20
@liudonghua123
Copy link
Contributor

I see this pr changed unix domain socket to websocket through network ipc. It just like bun inspect cli debugging doing.

I tested some simple demos of unix domain socket on windows and it works. How about to fix existing unix domain socket for windows, it's more high performance in my opinion. It's just my own thought. 😄

@Jarred-Sumner
Copy link
Collaborator

@liudonghua123 you're welcome to try getting unix domain sockets working when used in VSCode on Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[win] Debugging/running on VSCode on Windows doesn't work
4 participants