-
Notifications
You must be signed in to change notification settings - Fork 106
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
Removing unconfirmed message always results in an error #152
Comments
message = {};
x = [{}, message, {}];
x.indexOf(message); // Returns 1. There's pretty good test coverage for this project, too. Do you have an example that's causing the behavior you are seeing? |
My situation is more along the lines of this:
When logging the |
That would be true if you were in that situation - But... how would you ever get into that situation? |
I am not modifying Regarding |
I'm certainly interested in fixing this, but unless you can provide a test case or a sample repo that reproduces this, I'm not sure how I can help diagnose this. If your messages have some kind of unique identifier, you might try adding some logging to |
Unfortunately, the repo this module is being used in belongs to a private company so I cannot provide it as an example. In the meantime, I will try to create a test case that can replicate the issue I am experiencing and provide that to you. Thanks for the discussion and feedback. |
@zachmartin9 Hi, I've found myself running into something similar and have checked that I also am not modifying |
@jwalton some team mates have done some digging and found that it seems the logic on reconnection clears the This could lead to a race condition on reconnection that could produce this error. |
I was speculating with luddd3 that it might be such a race condition over here: #166 although it's not obvious to me how such a race condition would occur. We'd need to get the "disconnect" from amqplib, and then get a confirm after the disconnect (although maybe that's exactly what's happening).
We could go looking for the message in the
(Although I admit that sounds very unlikely). Hang on, I'll raise a PR... |
Oh wait, we only move messages from _unconfirmedMessages to _messages on the reconnect - it would have to be exactly that second scenario. :/ |
The unit tests for this had a fatal flaw - they assumed that if the connection dropped, we'd get nothing back for any in-flight messages. This isn't true, though - we'd actually get back an error from amqplib when the underlying connection fails. This fixes the tests to reflect this. If we rely on amqplib to reject such messages, then moving all messages from _unconfirmedMessages to _messages on a reconnect now becomes superfluous. I also reworked `_publishQueuedMessages()` to be more synchronous. As it stood, I had to add a lot of pointless delays in my tests to make sure that the `then` after publishing a message had time to run. fix #152
I think I have a fix for this in #178. I think you hit the nail on the head @michaelfitzhavey. That block of code was the problem. We should be relying on errors from amqplib on the disconnect to remove messages from the |
@michaelfitzhavey If you want to, you can review the fix too. I'd just like someone to eyeball this before I push it to prod. :) |
🎉 This issue has been resolved in version 3.5.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Currently when a message is acked/nacked, code was added to make sure the correct message is being removed from the sent messages queue. The function to achieve this is located below from the
src/ChannelWrapper.js
file:The issue is messages that are pushed to the queue are Objects and therefore the line of code
const toRemove = arr.indexOf(message)
will always result in-1
.The text was updated successfully, but these errors were encountered: