Skip to content

fix(triggerer): fix thread-safety in TriggerCommsDecoder.asend()#64869

Open
kalluripradeep wants to merge 1 commit intoapache:mainfrom
kalluripradeep:fix/triggerer-comms-threadsafe
Open

fix(triggerer): fix thread-safety in TriggerCommsDecoder.asend()#64869
kalluripradeep wants to merge 1 commit intoapache:mainfrom
kalluripradeep:fix/triggerer-comms-threadsafe

Conversation

@kalluripradeep
Copy link
Copy Markdown
Contributor

#64620 fix: TriggerCommsDecoder.asend() asyncio.Lock is not thread-safe

Description

The TriggerCommsDecoder used an asyncio.Lock to protect access to the communication socket. When called from a different event loop (e.g., via sync_to_async inside a trigger), asyncio.Lock would either fail to provide mutual exclusion or raise a RuntimeError.

This PR replaces the asyncio.Lock with an asynchronously-acquired threading.Lock, which is safe across all threads and loops. It also adds an explicit drain() to ensure reliability.

Changes

  • Replaced loop-bound asyncio.Lock with threading.Lock acquired via run_in_executor.
  • Added await self._async_writer.drain() to asend() to ensure reliable message delivery.

@kalluripradeep kalluripradeep force-pushed the fix/triggerer-comms-threadsafe branch from 810fc59 to 93552c2 Compare April 7, 2026 21:42
@kalluripradeep kalluripradeep reopened this Apr 7, 2026
@kalluripradeep kalluripradeep force-pushed the fix/triggerer-comms-threadsafe branch 3 times, most recently from 02bc550 to 867f4ad Compare April 8, 2026 11:15
Swapped the loop-bound asyncio lock for an asynchronous threading lock in TriggerCommsDecoder.asend() to ensure thread-safety across different event loops (e.g., from sync_to_async in triggers). Added a drain() call for reliable message delivery.

Includes a new high-concurrency unit test with a robust manual writer mock and socket mock to verify isolation and prevent CI regressions.

Closes apache#64620
@kalluripradeep kalluripradeep force-pushed the fix/triggerer-comms-threadsafe branch from 867f4ad to 840c212 Compare April 8, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant