#8591·effect

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

Author: MajorBreakfastCreated Sep 28, 2026Updated Sep 28, 2026
Labelsenhancement

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:

https://github.com/Effect-TS/effect/blob/cbfc7b422046111c439a69ecbce7fc4f4899789d/packages/effect/src/socket/Socket.ts#L1099-L1109

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.