You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prove native CDP server ownership before using a connection #170
Follow-up to #165, whose fix for the native_cdp_browser port race leaves one known gap.
Problem
The native CDP servers take a numeric port and bind it themselves, so native_cdp_browser cannot hold the port across the launch. It now restarts a server that exits with an "address in use" log, and it discards a connection if the server has already exited when the handshake returns.
A run can still connect to another process's browser if that process is a CDP server on the same port and our server has not exited when the handshake finishes. Parallel workers make a real CDP listener on that port plausible. The attempt would then be measured against the wrong browser with no error.
Options to check
Prove ownership with psutil: confirm that the listening socket belongs to the launched process. psutil is not in the headless-eval extra, so this needs a lockfile change.
Pass an inherited, already bound socket to the server. This needs server support, which has not been checked for Lightpanda, Moli or Obscura.
Done when
A connection is used only after it is proven to reach the launched server, with a test that has a real second CDP listener answer first.
28 of 30 runs yielded the other server's browser with no error. Our server exited with code 1 about 5 ms after the context was entered. 2 of 30 restarted.
Repeat on an idle host
30 of 30 restarted on a new port.
The two runs differ because the order is nearly tied: over 20 runs on the idle host, a failed bind exit took a median of 9.7 ms (8.5 to 10.5) and a handshake 9.3 ms (4.9 to 22.2). The order depends on the host, so this is not a rare case.
What #169 now does. If the server has exited when the caller finishes, the call fails with an error naming the exit code and log. This does not prove ownership or prevent the run on the other browser. It only stops the attempt from passing silently.
What the exit check still misses. A caller that finishes before the server exits returns with no error. I forced this by delaying the server start 100 ms through a wrapper script. A body of a local page plus 50 ms returned silently in 10 of 10 runs, and with 200 ms or 500 ms added, all 10 failed. Real fetches take longer than that, but only an ownership proof closes the gap.
The issue's "done when" is unchanged: use a connection only after it is proven to reach the launched server.
A related path that this issue does not cover. A listener that accepts a connection but never answers holds connect_over_cdp until the call deadline, because the handshake gets the full remaining budget. The review measured two processes started and a TimeoutError at 8.01 s with an 8 s budget. A shorter handshake timeout would let the restart help.
Activity
lanyue-llk commentedon Nov 3, 2026
Measurements from the #169 review rounds, all with real Playwright and a local page.
How often the wrong browser is reached. With Moli 1.1.17 and a second real Moli holding the forced port:
The two runs differ because the order is nearly tied: over 20 runs on the idle host, a failed bind exit took a median of 9.7 ms (8.5 to 10.5) and a handshake 9.3 ms (4.9 to 22.2). The order depends on the host, so this is not a rare case.
What #169 now does. If the server has exited when the caller finishes, the call fails with an error naming the exit code and log. This does not prove ownership or prevent the run on the other browser. It only stops the attempt from passing silently.
What the exit check still misses. A caller that finishes before the server exits returns with no error. I forced this by delaying the server start 100 ms through a wrapper script. A body of a local page plus 50 ms returned silently in 10 of 10 runs, and with 200 ms or 500 ms added, all 10 failed. Real fetches take longer than that, but only an ownership proof closes the gap.
The issue's "done when" is unchanged: use a connection only after it is proven to reach the launched server.
A related path that this issue does not cover. A listener that accepts a connection but never answers holds
connect_over_cdpuntil the call deadline, because the handshake gets the full remaining budget. The review measured two processes started and aTimeoutErrorat 8.01 s with an 8 s budget. A shorter handshake timeout would let the restart help.