Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve "Default max_queue blocks websocket cancellation with high traffic" #1556

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

btschwertfeger
Copy link

@btschwertfeger btschwertfeger commented Nov 27, 2024

Problem statement

If max_queue is not set to None and the connection closes while receiving a high volume of messages, it can trigger websockets.asyncio.client.messages.py:Assembler.paused == True. This results in self.pause() blocking termination, as frames are still pending processing. This issue arises only when the connection handles a significant influx of messages between the initiation of cancellation and its final acknowledgment.

Solution proposal

In order to avoid this behavior, we introduce Assembler.prepare_close() to continue any paused processing while setting Assembler.closing=True allows skipping further calls of Assembler.maybe_pause().

  # src.websockets.asyncio.connection.py:915... (see MR diff)
  async with asyncio_timeout_at(self.close_deadline):
+     self.recv_messages.prepare_close()
      await asyncio.shield(self.connection_lost_waiter)

Tasks:

  • add proper MR description and reasoning behind the change
  • add/update documentation (not needed I guess)
  • test the change properly
  • remove repro file (after first review)

Closes #1555

@btschwertfeger btschwertfeger force-pushed the 1555-default-max-queue-blocks-ws-cancellation branch from 15c940b to d51831c Compare November 28, 2024 16:34
@btschwertfeger btschwertfeger force-pushed the 1555-default-max-queue-blocks-ws-cancellation branch from d51831c to f4d0b20 Compare November 28, 2024 16:51
@btschwertfeger btschwertfeger force-pushed the 1555-default-max-queue-blocks-ws-cancellation branch from 6b64efd to c4b3d2b Compare November 28, 2024 17:11
@btschwertfeger btschwertfeger marked this pull request as ready for review November 28, 2024 17:12
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.

Default max_queue blocks websocket cancellation with high traffic
1 participant