Skip to content

Synchronize the Shoryuken::Client queue cache#1013

Draft
mensfeld wants to merge 3 commits into
mainfrom
fix/client-queues-thread-safe
Draft

Synchronize the Shoryuken::Client queue cache#1013
mensfeld wants to merge 3 commits into
mainfrom
fix/client-queues-thread-safe

Conversation

@mensfeld

Copy link
Copy Markdown
Collaborator

Client.queues cached queues with an unsynchronized @@queues[name] ||= Shoryuken::Queue.new(...). Building a queue makes SQS API calls, and that I/O releases the GVL, so concurrent first-access

  • the dispatch thread, processor-completion threads and worker threads all call Client.queues - built the same queue multiple times: redundant get_queue_url/get_queue_attributes calls, and a corrupt cache hash on JRuby/TruffleRuby.

Access to the cache (and the reset in sqs=) is now guarded by a class-level mutex. The lock is held during construction, but queues are built once at first access (and pre-cached at startup by validate_queues), so steady-state lookups are fast hash reads.

Coverage:

  • unit spec that 10 concurrent first-access callers build the queue only once (got 10 before the fix, since Queue construction sleeps/IO releases the GVL)

Client.queues cached queues with an unsynchronized
`@@queues[name] ||= Shoryuken::Queue.new(...)`. Building a queue makes
SQS API calls, and that I/O releases the GVL, so concurrent first-access
- the dispatch thread, processor-completion threads and worker threads
all call Client.queues - built the same queue multiple times: redundant
get_queue_url/get_queue_attributes calls, and a corrupt cache hash on
JRuby/TruffleRuby.

Access to the cache (and the reset in sqs=) is now guarded by a
class-level mutex. The lock is held during construction, but queues are
built once at first access (and pre-cached at startup by
validate_queues), so steady-state lookups are fast hash reads.

Coverage:
- unit spec that 10 concurrent first-access callers build the queue only
  once (got 10 before the fix, since Queue construction sleeps/IO
  releases the GVL)
@mensfeld mensfeld self-assigned this Jun 14, 2026
@mensfeld mensfeld added the bug label Jun 14, 2026
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7dfab0b-b264-4020-b380-56a0f50c09e4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/client-queues-thread-safe

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant