Skip to content

PartyServer WebSockets do not complete client-initiated close handshake #389

@ThomasKliszowski

Description

@ThomasKliszowski

Hello 👋

When using partyserver, a client-initiated WebSocket close reaches webSocketClose / onClose, but the client stays stuck in CLOSING and the connection timeouts where it should be gracefully closed by the server.

Repro

Minimal repro: https://github.com/ThomasKliszowski/partyserver-close-repro

Run:

pnpm install
pnpm dev

Then:

$ pnpm client

...
Client sends close(1000, "client initiated close")
Timed out after 2500ms waiting for the client close to finish. readyState=CLOSING

The server does receive the close event:

onClose {
  code: 1000,
  reason: 'client initiated close',
  wasClean: true,
  readyState: 2
}

But doesn't close the client's ws.

Excepted

$ pnpm client:ack

...
Client sends close(1000, "client initiated close")
Client received close event: code=1000, reason="client initiated close", readyState=CLOSED

Suspected Location

We never close the client's connection here:
https://github.com/cloudflare/partykit/blob/main/packages/partyserver/src/index.ts#L502-L525
(or in this.onClose depending on where you want to handle that)

Please let me know if you have any questions, thank you for looking into that 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions