Skip to content

fix(room-server): GlobalRateLimiter never held the lock during transmission#7

Open
tjdownes wants to merge 1 commit intodevfrom
fix/room-server-rate-limiter
Open

fix(room-server): GlobalRateLimiter never held the lock during transmission#7
tjdownes wants to merge 1 commit intodevfrom
fix/room-server-rate-limiter

Conversation

@tjdownes
Copy link
Copy Markdown
Owner

@tjdownes tjdownes commented May 1, 2026

Summary

  • GlobalRateLimiter was acquiring and immediately releasing the lock before transmission began, meaning concurrent transmissions were not actually serialised
  • Fix: hold the lock for the duration of the transmission

Test plan

  • Device test: verify only one message is on-air at a time under concurrent load

…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>
@tjdownes tjdownes force-pushed the fix/room-server-rate-limiter branch from 16b3076 to d1f0f1c Compare May 1, 2026 13:38
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