Fix RedisMessageQueue race condition#532
Conversation
Summary of ChangesHello @sij411, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical race condition within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a critical race condition in the RedisMessageQueue.listen() method, where pub/sub notifications could be missed. The fix correctly ensures that the message handler is attached synchronously after the Redis subscription is established, preventing messages from being lost during the timing window. The addition of a comprehensive and deterministic regression test suite, including a mock Redis client, is highly commendable and provides strong verification of the fix. The CHANGES.md entry clearly explains the issue and its resolution.
There was a problem hiding this comment.
Code Review
This pull request addresses a race condition in the RedisMessageQueue.listen() method, where pub/sub notifications could be missed if enqueue() was called immediately after listen() started. The fix involves awaiting the subscription before attaching the message handler, ensuring that no messages are missed. The pull request includes a deterministic regression test using mock Redis to reproduce the bug and verify the fix. The changes look good and the tests are well-written.
The message handler was attached inside an async callback, allowing a timing window where pub/sub notifications could be missed if enqueue() was called immediately after listen() started. The fix awaits subscribe() and attaches the handler synchronously. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The unsubscribe() call was async but not awaited, causing "Connection is closed" error when disconnect() was called while unsubscribe() was still pending. The original code didn't have unsubscribe() in the abort handler - disconnect() handles cleanup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Summary
RedisMessageQueue.listen()where pub/sub notifications could be missed ifenqueue()was called immediately afterlisten()startedTest plan
deno test --allow-all packages/redis/src/mq.race.test.ts- deterministic regression tests passdeno test --allow-all packages/redis/src/mq.test.tswith Redis - integration test passes (requiresREDIS_URLenv)Fixes #515
🤖 Generated with Claude Code