You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
π Bug Report β TCP socket closes with its closed promise in pending stateΒ #5653
I have a question regarding the TCP connect() API. In my case, I set the allowHalfOpen to true. When the TCP server starts the close handshake, I can see that tcpSocket.readable is closed and unlocked. Then I write one last data chunk to my own ReadableStream (which was pipeTo(tcpSocket.writable)) and close it with controller.close(). I notice that the TCP connection terminates as expected on the TCP server side, but tcpSocket.closed stays pending.
Is this behavior intentional? Or should I always explicitly call tcpSocket.close(), even if both streams are closed?
The current Cloudflare Workers implementation behaves as described above, specifically the ReadableStream needs to be read until completion for the closed promise to resolve, if the ReadableStream is not read then even if the server closes the connection the closed promise will not resolve.
The answer to the question is, yes, it is intentional.
Activity
rikka0w0 commentedon Dec 11, 2025
I found this: https://sockets-api.proposal.wintertc.org/, which seems to have more detail than the Cloudflare Worker documentation.
The answer to the question is, yes, it is intentional.
See also:
https://wicg.github.io/direct-sockets/#dom-tcpsocket-closed
But this specification (not used by worker) indicated that closed should be resolved when both readable and writable are closed.