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 truncated Chrome WS URL that results in intermittent Ferrum::DeadBrowserError #327

Merged
merged 1 commit into from
Jan 18, 2023
Merged

Fix truncated Chrome WS URL that results in intermittent Ferrum::DeadBrowserError #327

merged 1 commit into from
Jan 18, 2023

Conversation

francisbeaudoin
Copy link
Contributor

@francisbeaudoin francisbeaudoin commented Jan 17, 2023

Details

The Chrome WebSocket URL is read from the IO with the following:

begin
output += read_io.read_nonblock(512)
rescue IO::WaitReadable
read_io.wait_readable(max_time - now)
else
if output.match(regexp)
self.ws_url = output.match(regexp)[1].strip
break
end

As 512 bytes are read at a time, it occasionally occurs that we get a truncated WebSocket URL. For example, that is the output of the ws_url variable within a CI tests run that failed:

ws:https://127.0.0.1:35663/devtools/browser/a3603fc2-ed48-497d-9c1e-057b08f83aaf
ws:https://127.0.0.1:45503/devtools/browser/4db98447-c685-4a71-a7d5-146f2c2f24c5
...
ws:https://127.0.0.1:33327/devtools/browser/bab2421f-9b04-49af-8a50-e6802c21fa0c
ws:https://127.0.0.1:36173/devtools/browser/e1b4a3fa-c230-4422-ac82-ecf77858b33f
ws:https://127.0.0.1:42227/devtools/browser/907bc2f7-20ea-42e2-b1ea
ws:https://127.0.0.1:45059/devtools/browser/a36c4ddc-e6dc-4e65-bbe6-5d8ecbf653c5
...

As you can see, the ws:https://127.0.0.1:42227/devtools/browser/907bc2f7-20ea-42e2-b1ea one is truncated which eventually result in the driver raising a Ferrum::DeadBrowserError exception.

Proposed solution

The proposed fix is to enhance the regex by checking that the URL ends with a complete UUID.

Alternative solution

The logic could be changed to read the IO line by line instead of a fixed 512 bytes as Chrome is outputting with line breaks.

@route
Copy link
Member

route commented Jan 18, 2023

That's interesting, thank you Francis.

@route route self-requested a review January 18, 2023 06:22
@route route merged commit e2340b3 into rubycdp:main Jan 18, 2023
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.

2 participants