Skip to content

fix(client): clean up a failed start even when interrupted while closing - #738

Merged
route merged 1 commit into
mainfrom
fix/interrupted-start-cleanup
Nov 27, 2026
Merged

route merged 1 commit into
mainfrom
fix/interrupted-start-cleanup

Conversation

@route

@route route commented Nov 27, 2026

Copy link
Copy Markdown
Member

When Browser.new fails, e.g. a remote Chrome that accepts the WebSocket and never answers Browser.getVersion, Client#close waits up to a second for its message thread before it kills the thread and closes the dispatcher and the socket. An interrupt that lands in that second, such as an outer Timeout.timeout, Thread#raise, Thread#kill or Ctrl-C, skipped all of it. Every such attempt left 5 threads and an open socket behind, and GC.start didn't free them. For a browser Ferrum launched, Browser#start also skipped @process.stop.

With Browser.new(ws_url:, timeout: 1) against an endpoint that never answers:

Interrupt Before After
none 0 threads, 0 sockets 0 threads, 0 sockets
Timeout.timeout(1.5) 5 threads, 1 socket 0 threads, 0 sockets
Thread#raise at 1.4s 5 threads, 1 socket 0 threads, 0 sockets
Thread#kill at 1.4s 5 threads, 1 socket 0 threads, 0 sockets
  • Client#close kills the thread and closes the dispatcher and the socket in an ensure.
  • Browser#start stops the process in an ensure around closing the client.

@route
route force-pushed the fix/interrupted-start-cleanup branch from 00de1d6 to c733ba1 Compare November 27, 2026 16:15
Client#close killed its thread and closed the dispatcher and socket only after waiting up to a second for the
thread, so an interrupt landing in that wait (Timeout.timeout, Thread#raise) leaked the threads and the socket.
They run in an ensure now. Browser#start also stops the process when closing the client is interrupted.
@route
route force-pushed the fix/interrupted-start-cleanup branch from c733ba1 to 70904d2 Compare November 27, 2026 16:40
@route
route merged commit bdfb316 into main Nov 27, 2026
7 checks passed
@route
route deleted the fix/interrupted-start-cleanup branch November 27, 2026 17:14
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.

1 participant