-
Notifications
You must be signed in to change notification settings - Fork 5k
inspector: bump WebKit so Debugger.disable is idempotent on asserts builds #36851
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
Open
robobun
wants to merge
1
commit into
main
Choose a base branch
from
farm/de685579/debugger-disable-idempotent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { spawn } from "bun"; | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, isASAN, isDebug } from "harness"; | ||
|
|
||
| // InspectorDebuggerAgent::disable() used to call internalDisable() unconditionally, so a | ||
| // Debugger.disable on an already-disabled agent (or before any enable) re-ran | ||
| // m_debugger.setClient(nullptr) and tripped ASSERT(!!m_client != !!client) in | ||
| // JSC::Debugger::setClient. Frontends send Debugger.disable liberally on teardown, so this is | ||
| // an ordinary sequence. The assert is ASSERT_ENABLED-only, hence the skipIf. | ||
| test.skipIf(!isDebug && !isASAN)("Debugger.disable is idempotent and does not abort on asserts builds", async () => { | ||
| await using child = spawn({ | ||
| cmd: [bunExe(), "--inspect=127.0.0.1:0", "-e", "setInterval(()=>{},1000)"], | ||
| env: bunEnv, | ||
| stdout: "ignore", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| let stderr = ""; | ||
| const decoder = new TextDecoder(); | ||
| const { promise: urlPromise, resolve: resolveUrl, reject: rejectUrl } = Promise.withResolvers<URL>(); | ||
| const stderrDrained = (async () => { | ||
| for await (const chunk of child.stderr) { | ||
| stderr += decoder.decode(chunk); | ||
| const m = stderr.match(/ws:\/\/[^\s]+/); | ||
| if (m) resolveUrl(new URL(m[0])); | ||
| } | ||
| rejectUrl(new Error("inspectee exited before printing inspector URL:\n" + stderr)); | ||
| })(); | ||
|
|
||
| const url = await urlPromise; | ||
| const ws = new WebSocket(url); | ||
| const replies: Record<number, unknown> = {}; | ||
| try { | ||
| let nextId = 1; | ||
| let failed: unknown; | ||
| const pending = new Map<number, (x: unknown) => void>(); | ||
| const send = (method: string, params: object = {}) => | ||
| new Promise<unknown>(resolve => { | ||
| if (failed) return resolve(failed); | ||
| const id = nextId++; | ||
| pending.set(id, resolve); | ||
| ws.send(JSON.stringify({ id, method, params })); | ||
| }); | ||
| const fail = (r: unknown) => { | ||
| failed ??= r; | ||
| for (const p of pending.values()) p(r); | ||
| pending.clear(); | ||
| }; | ||
| ws.addEventListener("message", ev => { | ||
| const msg = JSON.parse(String(ev.data)); | ||
| if (typeof msg.id === "number" && pending.has(msg.id)) { | ||
| replies[msg.id] = msg; | ||
| pending.get(msg.id)!(msg); | ||
| pending.delete(msg.id); | ||
| } | ||
| }); | ||
| ws.addEventListener("close", ({ code, reason }) => fail({ closed: { code, reason } })); | ||
| ws.addEventListener("error", cause => fail({ error: String(cause) })); | ||
| await new Promise<void>((resolve, reject) => { | ||
| ws.addEventListener("open", () => resolve()); | ||
| ws.addEventListener("error", cause => reject(new Error("WebSocket error", { cause }))); | ||
| }); | ||
|
|
||
| // Disable before any enable: m_enabled is false at startup, so the agent must early-return. | ||
| await send("Debugger.disable"); | ||
| // Enable, disable, disable: the second disable must be a no-op, not a second setClient(nullptr). | ||
| await send("Debugger.enable"); | ||
| await send("Debugger.disable"); | ||
| await send("Debugger.disable"); | ||
| // The agent must still be usable afterwards. | ||
| await send("Debugger.enable"); | ||
| await send("Debugger.disable"); | ||
| } finally { | ||
| ws.close(); | ||
| child.kill(); | ||
| } | ||
|
|
||
| await Promise.all([child.exited, stderrDrained.catch(() => {})]); | ||
| if (child.signalCode === "SIGABRT") { | ||
| throw new Error( | ||
| `inspectee aborted on Debugger.disable (replies=${JSON.stringify(replies)}):\n${stderr.slice(-2000)}`, | ||
| ); | ||
| } | ||
| expect(replies).toEqual({ | ||
| 1: { id: 1, result: {} }, | ||
| 2: { id: 2, result: {} }, | ||
| 3: { id: 3, result: {} }, | ||
| 4: { id: 4, result: {} }, | ||
| 5: { id: 5, result: {} }, | ||
| 6: { id: 6, result: {} }, | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.