Skip to content

WebSocket: apply a write high-water mark, as #7487 did for TCP #8591

Open

Description

@MajorBreakfast

What is the problem this feature would solve?

A client that reads slowly makes the server hold everything sent to it. fromWebSocket's write calls ws.send(chunk) and succeeds at once, so nothing bounds that:

const write = (chunk: Uint8Array | string | CloseEvent): Effect.Effect<void, SocketError> =>
Effect.suspend(() => {
const ws = currentWS
if (ws === undefined) return latch.whenOpen(write(chunk))
try {
if (isCloseEvent(chunk)) {
ws.close(chunk.code, chunk.reason)
} else {
ws.send(chunk as string | Uint8Array<ArrayBuffer>)
}
return Effect.void

Workaround: I, or rather Claude :D, had to reach into ws through its private kWebSocket symbol to use ws.send's callback.

What is the feature you are proposing to solve the problem?

write hands the message to ws, then waits while the unsent bytes are past a writeHighWaterMark, as TCP writes wait for 'drain' since #7487. A message counts from ws.send until its callback.

The mark would come from an option or a context reference. request.upgrade takes no options, so a server-side socket needs the reference.

What alternatives have you considered?

  • A non-blocking mark: hasRoom and drained on the Writer.
  • A write that completes once written, leaving the counting to every caller.

Activity

  1. changed the title [-]WebSocket `write` should wait until `ws` has written the frame[/-] [+]WebSocket writer: High-water mark (without blocking)[/+] on Sep 28, 2026
  2. changed the title [-]WebSocket writer: High-water mark (without blocking)[/-] [+]WebSocket: apply a write high-water mark, as #7487 did for TCP[/+] on Sep 28, 2026
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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions