Interrupt blocked queue puts during sync WebSocket teardown

Merged
KL
1mo ago
+63-6

When the sync session's bounded events queue is full, the background receive thread blocks on queue.Queue.put(). close() never drains the queue, so the .join() in __exit__ hangs forever whenever more than queue_size unread messages are pending.

__exit__ now unblocks the pending put() before waiting for the background threads. On Python 3.13+ it calls Queue.shutdown(immediate=True); on older versions it discards queued events until the threads exit. The fallback can go once we drop Python 3.12. Nothing else changes. The async session is unaffected, since its cancel scope already cancels pending sends.

test_exit_with_full_queue hangs on main and passes here.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.