-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call handleMessage in sequence, instead of using Promise.all() #248
Conversation
Removed await Promise.all() in favor of for (...) { await } Promise.all could result in messages not being handled in order.
The library by default only polls and processes one message at the time, making this a non-issue. Not a bug. |
In our codebase, we initialize the Consumer with a Initially, we tried using But now we have another problem. If one of the messages in our queue throws an error, all messages from the batch, even the already successfully processed ones, are invalidated. This issue is mentioned in #189 and #245, along with a workaround. I see multiple ways of resolving issues #189 and #245:
|
If there is an issue only when you change some parameter it does not mean it's not a bug. It's a bug which emerges in some specific conditions but it's still a bug. And pretty critical one. I've been struggling with this as well and it caused a lot of troubles. |
Can you make a status if it will merged or not? at least users will get a clear view if they have to be fork it |
Reading this comment: #248 (comment) I think this was sufficiently answered and given the age, I'm unsure if the requirement still exists. Should you still think this is still an issue / requires better documentation, please open a new PR. |
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Description
I removed
await Promise.all()
in favor offor (...) { await }
, because Promise.all could result in messages not being handled in order.Motivation and Context
Message ordering is important. The same can be said about the order in which messages are processed. In many cases, if not most, messages need to be processed one after the other, in the order they arrive.
Promise.all() runs handlers for all messages "in parallel". Well, in fact, it's in sequence until the first
await
in the handler's code. However, since handleMessage is declared to be an async function, I presume it will usually have anawait
. In practice, that means that messages are not processed in sequence, waiting for the previous message to be finished, but all at once.My code fixes the issue by eliminating the parallelism and instead introducing a for loop in which we await the completion of each message handler before continuing.
This keeps the order in which handleMessage is called, but it changes the order of when it finishes. It is therefore potentially a breaking change.
Types of changes
Checklist: