Repository navigation
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
This was referenced Oct 24, 2026
connect() sent subscription changes only when its receive loop came round again, after the next message or the one-second recv timeout. On a quiet feed, a subscribe() took up to a second to reach the server. Each connection now has one task that sends subscription changes. It starts after authentication by sending the whole scheduled set, then waits on an asyncio.Event. subscribe(), unsubscribe() and unsubscribe_all() set the event through call_soon_threadsafe(), which never blocks the caller. Being the only sender, the task never interleaves messages, and it merges a burst of changes into one subscribe and one unsubscribe message. The receive loop still checks schedule_resub on every turn, now to wake the task, so code that changes scheduled_subs itself and sets the flag keeps working. An error other than a closed connection ends the task and is raised by connect(), as before. The task is stopped when the connection ends. The receive path is otherwise unchanged. Sending while another coroutine waits in recv() on the same connection is safe in websockets 14.0 through 17.3, the current release (websockets/asyncio/connection.py). recv() only reads from the message assembler (14.0 L270, 14.2 L294, 15.0.1 L303, 16.1.1 L305, 17.3 L298), whose only concurrency check rejects a second concurrent reader (asyncio/messages.py, Assembler.get: 14.0 L142, 14.2 L141, 15.0.1 L150, 16.1.1 L149, 17.3 L148). send() waits only for a fragmented send in progress (fragmented_send_waiter, named send_in_progress in 16.1.1 and 17.3: 14.0 L427, 14.2 L451, 15.0.1 L469, 16.1.1 L472, 17.3 L466) before writing through send_context() (14.0 L434, 14.2 L458, 15.0.1 L476, 16.1.1 L479, 17.3 L473).
chipkent
force-pushed
the
fix/ws-thread-safe-subscribe
branch
from
October 24, 2026 14:54
a444d2c to
90a5fb6
Compare
chipkent
force-pushed
the
feat/ws-immediate-subscriptions
branch
from
October 24, 2026 14:54
8247c09 to
0c0a16c
Compare
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #<issue: F1a-delay>
Builds on #20.
connect()sent subscription changes only when its receive loop came round again, after the next message or the 1-second receive timeout. On a quiet feed, asubscribe()took up to a second to reach the server.subscribe(),unsubscribe()andunsubscribe_all()wake it throughloop.call_soon_threadsafe(), which never blocks the caller.schedule_resubon every turn, so settingscheduled_subsandschedule_resubdirectly still works.recv()is safe in websockets 14.0 through 17.3, the current release; the commit message cites the lines.Throughput is unchanged: with a local server sending 20 trades per message, the median time per message is within 1% of
masteron 3.10 and 3.14 (benchmark script available on request).Tests
test_sender.py: with the receive timeout removed, a change made from another thread still reaches an idle connection (fails onmaster), and direct writes toscheduled_subsstill work.make testandmake lintpass on 3.10 and 3.14.