Skip to content

Conversation

@mmenozzi
Copy link
Member

If for a given ProducerInstance for a flow, the method ProducerInstance::produceAndQueueJobs() is called concurrently multiple times (for example because the produces is an HttpRequestProducer and the same request arrives multiple times at the same time) there is the chance that same jobs are enqueued multiple times or, worst, some jobs are lost.

This is because the "batch" of the QueueManager is always the same and is shared between the multiple calls of ProducerInstance::produceAndQueueJobs().

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a race condition that occurs when ProducerInstance::produceAndQueueJobs() is called concurrently for the same flow (e.g., when multiple HTTP requests arrive simultaneously for an HttpRequestProducer). The race condition could cause jobs to be enqueued multiple times or lost entirely due to concurrent access to a shared batch in the QueueManager.

Key changes:

  • Introduced batch IDs (UUIDs) to isolate concurrent batches in the QueueManager
  • Modified the ProducerQueueManagerInterface to require a batchId parameter for enqueue and flush operations
  • Updated QueueManager to maintain separate batches per batchId instead of a single shared batch

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/Integration/HttpRequestProducerAndWorkerTest.php Added new test case to verify concurrent HTTP requests are properly handled without job loss or duplication
src/Service/QueueManager.php Refactored from single batch array to multi-batch map keyed by batchId, updated all batch operations to use batchId parameter
src/Service/ProducerQueueManagerInterface.php Extended interface methods (enqueue and flush) to accept batchId parameter for batch isolation
src/ProducerInstance.php Generate unique UUID for each produceAndQueueJobs invocation and pass it to enqueue/flush operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mmenozzi mmenozzi force-pushed the queue-manger-race-condition-fix branch from 3db8dc7 to d1d70a7 Compare January 7, 2026 17:56
@mmenozzi mmenozzi requested a review from azambon January 7, 2026 17:56
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.

3 participants