Skip to content

fix(websocket): bound slow-consumer output buffers - #225

Open
loks0n wants to merge 1 commit into
mainfrom
codex/port-websocket-slow-consumer-buffer
Open

fix(websocket): bound slow-consumer output buffers#225
loks0n wants to merge 1 commit into
mainfrom
codex/port-websocket-slow-consumer-buffer

Conversation

@loks0n

@loks0n loks0n commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Clients that stop reading can make Swoole retain enough outgoing data across connections to exhaust a realtime container. Port utopia-php/websocket#31 into the monorepo: default each connection's output buffer to 512KB, apply the limit to the listen port before startup, disable send_yield when capped, and disconnect clients when a push fails so message loss is not silent.

The constructor accepts socketBufferSize; passing 0 retains Swoole's default buffer size and yield behavior. Failed pushes still disconnect clients. The new default changes behavior for clients that fall behind, so this needs to be accounted for when choosing the release version.

Adds README guidance and an end-to-end regression that stops reading from one client, fills its outgoing buffer, and verifies that it is disconnected while another client still exchanges messages. This test fails both with the cap removed and with disconnect-on-failure removed.

Validation:

  • bin/monorepo check websocket — Pint, PHPStan, and Rector pass.
  • bin/monorepo test websocket — 9 unit tests and 3 end-to-end tests pass with real Swoole and Workerman servers.
  • Both regression mutation checks fail at the expected stalled-client assertion; the restored implementation passes.
  • bin/monorepo validate, Vale for the package README, and git diff --check pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant