Skip to content

Fix Network failures#17381

Merged
AutomatedTester merged 2 commits intotrunkfrom
network_failures
Apr 24, 2026
Merged

Fix Network failures#17381
AutomatedTester merged 2 commits intotrunkfrom
network_failures

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

🔗 Related Issues

💥 What does this PR do?

🔧 Implementation Notes

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):
    • What was generated: helped review failures quicker
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)
  • Bug fix (backwards compatible)

AutomatedTester and others added 2 commits April 24, 2026 14:46
…rror

When network.beforeRequestSent callbacks fire during a page load they run
in daemon threads (via Thread.start() in _process_message). If those
callbacks call continue_request() -> execute() concurrently with the
main thread also inside execute(), two bugs trigger:

1. self._id was incremented without a lock, and current_id was captured
   *after* self._ws.send(). A context switch between send() and the
   capture let another thread increment self._id so current_id picked up
   the wrong value, causing one thread to wait for a message ID it would
   never receive.

2. _wait_until() returns silently on timeout, so the subsequent
   self._messages.pop(current_id) raised an opaque KeyError: 24 instead
   of a useful exception.

Fix:
- Add self._id_lock (threading.Lock) and atomically increment + capture
  current_id inside the lock, before serialising the payload.
- Use current_id for payload["id"] instead of self._id.
- After _wait_until(), raise WebDriverException with a clear message when
  the expected response never arrived.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The generated AuthRequiredParameters dataclass only has a 'response'
field, losing the 'request' field that contains the BiDi request ID
needed to call network.continueWithAuth.

_auth_callback in add_auth_handler extracts request_id via:
    raw.get("request", {}).get("request")

When the event is deserialized to AuthRequiredParameters the 'request'
key is filtered out by _EventWrapper.from_json (only valid dataclass
fields are kept), so request_id is always None and continueWithAuth
is never sent.  Chrome then holds the intercepted request open
indefinitely, causing browsingContext.navigate to time out after 30 s.

Fix: add 'auth_required' to extra_events in the network module's
bidi_enhancements_manifest entry with event_class='dict'.  The generator
appends extra_events at the end of the EVENT_CONFIGS dict literal, so
this duplicate key overrides the CDDL-generated entry.  _EventWrapper
then returns the raw params dict (camelCase keys intact) and
request_id is extracted correctly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 14:22
@selenium-ci selenium-ci added the C-py Python Bindings label Apr 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves reliability of the Python WebDriver BiDi transport and network event handling, targeting observed network-related failures in BiDi workflows.

Changes:

  • Make BiDi command ID generation thread-safe in WebSocketConnection.execute().
  • Raise a clearer WebDriverException when a BiDi command response times out (instead of failing later with a KeyError).
  • Override the network.authRequired event mapping to pass raw event params (dict) so auth handlers can access the request ID.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
py/selenium/webdriver/remote/websocket_connection.py Adds a lock for _id and improves timeout error handling when awaiting BiDi command responses.
py/private/bidi_enhancements_manifest.py Overrides auth_required event config to use raw dict params so auth handlers receive required fields (e.g., request).

Comment thread py/selenium/webdriver/remote/websocket_connection.py
Comment thread py/selenium/webdriver/remote/websocket_connection.py
@AutomatedTester AutomatedTester merged commit 7135a45 into trunk Apr 24, 2026
46 of 47 checks passed
@AutomatedTester AutomatedTester deleted the network_failures branch April 24, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants