Repository navigation
feat(client): add :keepalive_interval to keep the connection active during long waits - #671
Open
bensheldon wants to merge 2 commits into
Open
bensheldon wants to merge 2 commits into
bensheldon wants to merge 2 commits into
Conversation
…uring long waits A proxy between Ruby and Chrome with an idle timeout (e.g. Heroku's router at 55 seconds) drops the websocket when a single wait sends nothing for longer than that, such as a slow Page.navigate response or a navigation started by a click. With :keepalive_interval set, these waits are split into slices with a Browser.getVersion command sent between them. The total wait is still bounded by :timeout.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When Chrome is reached through a proxy or router with an idle timeout, any Ferrum wait longer than that timeout drops the connection. Heroku's router, for example, closes websocket connections that are idle for 55 seconds unless "either client or server [sends] an occasional ping packet". Many load balancers default to 60 seconds.
Two waits send nothing over the websocket for their whole duration:
Client#send_messagewaiting for a slow command response, e.g.Page.navigateto a page that takes a long time to respond.Page#commandwaiting for a navigation started by the command, e.g. a click that submits a slow form.With
timeout: 120, either wait can outlast the proxy's limit. The only workaround today is to keep:timeoutbelow that limit and retry in application code. Retrying a click can submit a form twice.This adds an opt-in
:keepalive_intervaloption (defaultnil, no behavior change):When set, both waits are split into slices of at most
keepalive_intervalseconds, and aBrowser.getVersioncommand is sent between slices. The total wait is still bounded by:timeout, andTimeoutErroris raised at the same point as before.Browser.getVersionis used because it's read-only and works at the browser level, so it still works while the page is between documents. As a real CDP round-trip, it creates traffic on every hop between Ruby and Chrome, including intermediate proxies that might answer websocket ping frames themselves.