Skip to content

πŸ› Bug Report β€” TCP socket closes with its closed promise in pending stateΒ #5653

Closed

Description

@rikka0w0

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?

Activity

  1. rikka0w0 commented on Dec 11, 2025

    @rikka0w0
    Author

    I found this: https://sockets-api.proposal.wintertc.org/, which seems to have more detail than the Cloudflare Worker documentation.

    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.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions