Dealing with a message handler that is unresponsive
Creating issue as per skype discussion with @SimonCropp ...
What happens if a dev writes a msg handler that has Thread.Sleep(forever) in it? Or if the msg handler sync calls a badly behaved service with a stupidly long timeout.
Is there any way to terminate runaway/rogue threads in the host?
When using the DTC this is obviously handled by DTC with a timeout. But I would expect this to be a problem common to all non-DTC brokered transports - would be preferable to have this handled at an NSB level rather than within msg handlers.
@thirkcircus - Tell dev not to have a forever sleep in the handler? :) Monitor CriticalTime for the endpoints and see why messages take too long to process and identify the stupidly long timeouts and fix it?
Or if the msg handler sync calls a badly behaved service with a stupidly long timeout.
So if you are calling a 3rd party that may take a long time, then you need to specify a timeout for that 3rd party call, exactly the same as when you calling http and you can(should always) specify a timeout.
What happens if a dev writes a msg handler that has Thread.Sleep(forever) in it?
Wouldn't this scenario be considered a bug and hopefully picked up in testing?
Is there any way to terminate runaway/rogue threads in the host?
No there isn't and I'm not sure that is the responsibility of the framework, there can be situations where this scenario is fine. You can also enable SLAs and keep an eye on CriticalTime performance counter.
BTW, even though DTC has a timeout, the timeout exception is only triggered when the code calls Commit/Rollback!
I concede, there may be a usage for this feature, even thought at this stage I have no idea how we would implement it!
Side note: I would use simon's static type replacer for fody and replace every Thread.Sleep call with a replacer which throws an EvilStuffUsedHereException ;)
Am 24.10.2013 um 00:19 schrieb Justin Thirkell [email protected]:
Creating issue as per skype discussion with @SimonCropp ...
What happens if a dev writes a msg handler that has Thread.Sleep(forever) in it? Or if the msg handler sync calls a badly behaved service with a stupidly long timeout.
Is there any way to terminate runaway/rogue threads in the host?
— Reply to this email directly or view it on GitHub.
for some context @danielmarbach is referring to Inoad https://github.com/Fody/Ionad
What are the use cases for this? Other than bad developers? In addition to the Critical time, we also do have the EndpointSLAViolationCountdown perf counter as well to indicate to Ops that this handler is taking too long. What advantages do we see in having this feature? So, in the cases where the handler takes too long, rather than get notified, we want to kill that handler? Just trying to understand?
Doesn't critical time & the perf counter only report back once the message has completed?
@chrisbednarski - yes, but aren't we talking about long thread sleeps here, or long timeouts on sync calls. eventually they end? I am trying to understand the scenarios where this feature will be useful.
@indualagarsamy Thread.Sleep(forever) will never end. If there's no timeout that kills the worker thread, the worker thread will be blocked forever. I agree that scenarios are unclear!
a more likely case is someone has done a while(true) loop and there is a bug in the exit clause. this will never end and may not be picked up in a core review or testing.
So to close off my part of the issue - I was asked the question by co-workers and just wasn't sure of the answer. I now have a good-enough answer thanks (discovery -> use the msg-level monitoring provided. fix -> recode and redeploy the service). Whether there is still an actionable issue to come out of this I'm happy to let you guys thrash it out...
@distantcam applying your knowledge of async/threading is this something we should attempt to solve in NSB?
Well, we could wrap calling the handler in a task, and use Task.Wait to timeout the call. All that's needed is a default timeout that could be configurable.
If the handler times out, treat it as an error?
I would favor going for an async pipeline and async handler
Am 20.10.2014 um 12:10 schrieb Cameron MacFarland [email protected]:
Well, we could wrap calling the handler in a task, and use Task.Wait to timeout the call. All that's needed is a default timeout that could be configurable.
If the handler times out, treat it as an error?
— Reply to this email directly or view it on GitHub.
With v6 implementors of handlers have to possibility to use cooperative cancellation provided by the .NET framework for their custom code. In the future, we might even expose the cancellation token source and token provided by the transport for each message received. From the perspective of rogue message handler detection there is not much we can do since each transport has its own way of dealing with long running operations (peek lock, no restriction, transaction timeouts...). Closing this.