Skip to content

fix(threading): guard client-side state with a dispatch lock - #3387

Closed
Yury Semikhatsky (yury-s) wants to merge 3 commits into
mainfrom
dispatch-lock
Closed

Yury Semikhatsky (yury-s) wants to merge 3 commits into
mainfrom
dispatch-lock

Conversation

@yury-s

Copy link
Copy Markdown
Member

Summary

  • Adds 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, Frames and Contexts return 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 on main).
  • Route, binding, locator handler, WebSocket route, HAR router and CDP event registries are written and read under the lock. The route Times count moves under the same lock as the expiry check, so two matching requests handled concurrently cannot both pass it. The tracing counter uses Interlocked.

The check-then-subscribe races in the navigation waits (#3364) are addressed in a separate PR on top of this one.

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.
@pavelfeldman

Copy link
Copy Markdown
Member

I think this requires a systematic approach rather than patching. Let's document the port architecture and perform the line-by-line transformation.

@dgozman

Copy link
Copy Markdown
Collaborator

Closing in favor of #3453.

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.

3 participants