Skip to content

fix(chromium): reach CDP on ports Node's fetch refuses - #1937

Open
pcbeingused333 wants to merge 1 commit into
software-mansion:mainfrom
pcbeingused333:fix/cdp-fetch-bad-port-1935
Open

pcbeingused333 wants to merge 1 commit into
software-mansion:mainfrom
pcbeingused333:fix/cdp-fetch-bad-port-1935

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #1935

Cause: fetchJson in packages/tool-server/src/chromium-server/cdp-session.ts probes CDP with undici fetch. undici rejects the Fetch spec's bad-port list (6000, 10080, and the rest) before opening a socket. electronPort accepts 1024–65535, and waitForCdpReady treats every probe failure as transient, so boot retries for the full 30s, kills the app, and reports that the connection failed. The same probe is why an app already listening on one of those ports is never discovered through ARGENT_CHROMIUM_PORTS.

Fix: When undici fails with bad port on a port at or above 1024, repeat that one GET with node:http, which does not apply the bad-port block. A listener is then reached on the first probe, so boot returns instead of waiting out the deadline, and discovery sees the app. Ports below 1024 stay refused, so a probe of port 1 still fails before any socket. Connection errors, timeouts, non-2xx responses, and non-JSON bodies keep the same failure classification.

Test: packages/tool-server/test/chromium-discovery.test.ts starts a CDP stub on a blocked port (10080, or the next free port in that list) and expects discoverChromiumDevices to return it. That case fails on main and passes with this change.

Reproduction: a CDP listener on 127.0.0.1:10080 answering /json/version and /json/list. On main, discovery of that port returns nothing, and boot-device with electronPort: 10080 waits out the readiness timeout with CHROMIUM_ELECTRON_CDP_TIMEOUT, the cause chain ending in bad port. After this change the probe reads the listener.

This change was prepared with AI assistance (Claude).

undici rejects the Fetch bad-port list before dialing, so a readiness
probe of electronPort 6000 or 10080 failed at once and boot retried
until the deadline. Repeat that GET with node:http, which can dial it.

This branch has not been deployed

No deployments
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.

boot-device on an electronPort that fetch blocks (6000, 10080, ...) waits out the timeout and blames the connection

1 participant