fix(room-server): GlobalRateLimiter never held the lock during transmission#7
Open
fix(room-server): GlobalRateLimiter never held the lock during transmission#7
Conversation
…ission The acquire() method used `async with self.lock:` which releases the lock the moment the method returns — before the caller has sent anything. The comment even said "Lock is now held" but it was not. Concurrently running push_post_to_client() coroutines could therefore all pass through acquire() and transmit at the same time, defeating the entire purpose of the limiter. release() only updated last_release_time but never released any asyncio.Lock object (there was nothing to release), so the minimum-gap enforcement was also broken. Fixes: - acquire() now calls `await self.lock.acquire()` manually so the lock stays held across the caller's await send_packet() call. - release() calls self.lock.release() in addition to recording the timestamp. - Remove _global_push_lock = asyncio.Lock() at module level. It was dead code (never referenced anywhere) and would raise DeprecationWarning / RuntimeError on Python 3.10+ because asyncio.Lock() created outside a running event loop is not attached to any loop. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
16b3076 to
d1f0f1c
Compare
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.
Summary
GlobalRateLimiterwas acquiring and immediately releasing the lock before transmission began, meaning concurrent transmissions were not actually serialisedTest plan