Messages retried through SLR breaks worker ready mechanism in scale out scenario
I work with mariusin79 in #1115 and I've finally been able to track down the issue as described below. I've created a new issue as the title and description of #1115 aren't very relevant for the actual problem. #1115 can be closed.
Any message put in an input queue to a distributor which has the header NServiceBus.Retries on it will reduce the number of available workers by 1. If you put more such messages in than available workers in storage the processing grinds to a halt.
When the worker gets the message the eventhandler in NServiceBus.Distributor.ReadyMessagesSender is run:
EndpointTransport.FinishedMessageProcessing += (a, b) =>
{
if (((IBus)Bus).CurrentMessageContext.Headers.ContainsKey(NServiceBus.Headers.Retries))
return;
SendReadyMessage(1);
};
The problem is that any message coming in to a worker with the header set will NOT send a ready message back, even though it should.
Now the interesting part is why this would ever happen. Retries are done locally on the worker and when a message is finally put on the error queue it will not have the Retries header set, unless second level retries are enabled. With SLR enabled the message do indeed have the Retries header set when they are put in the error queue. If you then ~~ReturnToSourceQueue or~~ use Queue Explorer to put the messages back in distributor input queue, it eats a worker.
Repro is simple:
- Use the Scaleout-sample.
- Make the messagehandler throw an exception.
- Send some messages and let them make it through retries and second level retries. They will end up on the error queue.
- Drag them back to the orders.handler queue and they will eat one available worker for every message.
This scenario pops up regularly for us in production when our operations team drag messages from error queues back to the input queues.
I'd also like to ask the NServiceBus team to consider fixing this in 3.3.X as it's hitting us in production regularly. I know 4.0 is right around the corner, but that's a major upgrade for us and not something we implement lightly. We need a stable 3.3.X-release.
Just checking: If you remove the header (NServiceBus.Headers.Retries) before sending it back it works?
Yupp, just checked with the repro. Remove the header and it works as expected.
I thought ReturnToSourceQueue does that by default ?
On Friday, April 26, 2013, Jan Ove Skogheim Olsen wrote:
Yupp, just checked with the repro. Remove the header and it works as expected.
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/1133#issuecomment-17064313 .
Regards John Simons NServiceBus
Okay, that might be. I assumed ReturnToSourceQueue just moved the message. We use Queue Explorer for putting stuff back on the original queue.
We should fix this regardless, this bug seems to have been introduced in #571
On Fri, Apr 26, 2013 at 12:19 PM, Jan Ove Skogheim Olsen < [email protected]> wrote:
Okay, that might be. I assumed ReturnToSourceQueue just moved the message. We use Queue Explorer for putting stuff back on the original queue.
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/1133#issuecomment-17065635 .
http://andreasohlund.net http://twitter.com/andreasohlund
Agree
On Friday, April 26, 2013, Andreas Öhlund wrote:
We should fix this regardless, this bug seems to have been introduced in #571 https://github.com/NServiceBus/NServiceBus/issues/571
On Fri, Apr 26, 2013 at 12:19 PM, Jan Ove Skogheim Olsen < [email protected] <javascript:_e({}, 'cvml', '[email protected]');>> wrote:
Okay, that might be. I assumed ReturnToSourceQueue just moved the message. We use Queue Explorer for putting stuff back on the original queue.
— Reply to this email directly or view it on GitHub< https://github.com/NServiceBus/NServiceBus/issues/1133#issuecomment-17065635>
.
http://andreasohlund.net http://twitter.com/andreasohlund
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/1133#issuecomment-17067620 .
Regards John Simons NServiceBus
Yeah, I think it's fair to say that the distributor mechanism shouldn't be dependent on whether SLR is enabled or not and/or which tool you use for moving messages back from the error queue.
So basically the fix here is to always do retries through the distributor, even the first level ones? And what's the check for queue name ending in ".worker"?
The first level ones are fine since they rollback to the same q (the rollback includes the "ReadyMessages" as well). The ".worker" thing is a bit unfortunate but I can't find a better way for now to figure out that the current receiver is the one that is feeding messages in to the local worker in the distributor. I'm doing some additional tests and I found another flaw that needs to be fixed. We need to do the same redirection for the remote workers as well => to force them to process SLR's via the distributor as well. Stay tuned
@janovesk there is a 3.3.7 beta build available that should fix this issue. Any chance you can verify on your end?
http://builds.nservicebus.com/viewLog.html?buildId=3225&tab=buildResultsDiv&buildTypeId=bt46
https://nuget.org/packages/NServiceBus/3.3.7-beta1
Sure, I'll give it a go.
Looks good, I'm unable to reproduce the error here with 3.3.7-beta1.
Excellent, I'll do a few more tests and then we'll promote this to a official 3.3.7
Sent from my iPhone
On 30 apr 2013, at 13:28, Jan Ove Skogheim Olsen [email protected] wrote:
Looks good, I'm unable to reproduce the error here with 3.3.7-beta1.
— Reply to this email directly or view it on GitHub.
Do you have an ETA on 3.3.7, andreasohlund?
Today hopefully
On Wed, May 8, 2013 at 9:49 AM, Jan Ove Skogheim Olsen < [email protected]> wrote:
Do you have an ETA on 3.3.7, andreasohlund?
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/1133#issuecomment-17591302 .
http://andreasohlund.net http://twitter.com/andreasohlund