cloudflare / workerd

The JavaScript / Wasm runtime that powers Cloudflare Workers
https://blog.cloudflare.com/workerd-open-source-workers-runtime/
Apache License 2.0
6.11k stars 290 forks source link

Fix shutdown timing in inspector protocol. #2294

Closed kentonv closed 3 months ago

kentonv commented 3 months ago

messagePump() is defined as:

return receiveLoop().exclusiveJoin(dispatchLoop()).exclusiveJoin(transmitLoop());

receiveLoop() is responsible for receiving the final close message, and transmitLoop() is responsible for replying to it. This creates a race where receiveLoop() might receive the close message and exit before transmitLoop() can reply.

We can fix this by having receiveLoop() pause after receiving a close message. transmitLoop() will reply to it and then return, at which point receiveLoop() will be canceled anyway.