Repository navigation
fix(threading): guard client-side state with a dispatch lock - #3387
Closed
Yury Semikhatsky (yury-s) wants to merge 3 commits into
Closed
Yury Semikhatsky (yury-s) wants to merge 3 commits into
Yury Semikhatsky (yury-s) wants to merge 3 commits into
Conversation
Pages, ChildFrames, Workers, ServiceWorkers, Frames and Contexts now return copies taken under Connection.DispatchLock, and the message pump adds and removes elements under the same lock. Enumerating them while the pump mutates them can no longer throw or observe a torn copy.
Both loops threw "Collection was modified" when the getters handed out the live lists.
…dispatch lock Routes, bindings, locator handlers, WebSocket routes, HAR routers and CDP session events are written by the caller and read by the pump or by pool threads. Both sides now take Connection.DispatchLock. The route Times count moves under the same lock as the expiry check, so two matching requests handled concurrently cannot both pass it, and the tracing counter uses Interlocked.
Yury Semikhatsky (yury-s)
force-pushed
the
dispatch-lock
branch
from
October 22, 2026 23:23
365e873 to
84d33c0
Compare
Yury Semikhatsky (yury-s)
marked this pull request as ready for review
October 22, 2026 23:33
Member
|
I think this requires a systematic approach rather than patching. Let's document the port architecture and perform the line-by-line transformation. |
Collaborator
|
Closing in favor of #3453. |
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.
Summary
Connection.DispatchLock, taken by the message pump around every write to client-side state that user code can read, and by the readers of that state. Critical sections are synchronous and never run user code.Pages,ChildFrames,Workers,ServiceWorkers,FramesandContextsreturn snapshots taken under the lock, and the pump adds and removes under it. Iterating them while the pump mutates them no longer throws (two regression tests, both fail onmain).Timescount moves under the same lock as the expiry check, so two matching requests handled concurrently cannot both pass it. The tracing counter usesInterlocked.The check-then-subscribe races in the navigation waits (#3364) are addressed in a separate PR on top of this one.