-
Notifications
You must be signed in to change notification settings - Fork 115
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
Exception handling in IDLE #70
Comments
Turns out that was only half the battle - one inheritent problem in the lib is concurrent access. Try launching a couple of imap operations in the newmail handler will get you into severe trouble because the Idle loop. Here's a scenario that will mess things up big time: Subscribe for new emails, with an event handler that does the following:
See it bomb out. There's a variety of things here. First of, using
Does not guarantee that whomever tries to acquire the lock while somebody has already acquired it, will get it in the order that access was requested. So if A has the lock, and B and C try to access it, C may get it before B even though requested it first. So, in the above scenario, things may not terminate as planned and you might end up in a situation where idle is restarted when the connection was already closed (which of course causes all kinds of havoc). I've had to solve a similar problem with asynchronous execution that needed to follow a specific order - unfortunately as it is task based, it cannot directly be transferred here.However, using something like a QueuedLock (http://pastebin.com/BTdPY2UZ) should do the trick. So, all the lock(sequenceLock) would need to be replaced by
As a quick fix I did the following
|
Hi, the IssueNoop method is tied to the Elapsed event of the noopTimer and executes in the context of a threadpool thread. As a (in this case convenient) side-effect, the timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event; You're right about the GetHighestUID in the dispatcher thread though. I tried to re-produce the scenario you described above, but haven't had any luck.
|
Suppose you have IDLE up and running, and the noopTimer.Elapsed fires. And something goes wrong in IssueNoop. Your program goes boom and it's all over (uncaught exception bringing the entire application down). In Issue #51 we have a solution to handle errors in the IdleLoop - but that's only half the battle. If something goes wrong in IssueNoop, it still brings the house down.
The easiest way to get around that is simply wrap the whole IssueNoop in a try/catch, but that doesn't work with the rest of the design.
I think to be properly resilient in the IDLE scenario, the lib would need to detect conectivvity issue, provide a reconnect mechanism (e.g. when starting IDLE you could have a parameter telling the lib to reconnect if there's an issue, and if not, give an event to notify the user about the issue).
The same problem can arise in the EventDispatcher - if there's an issue in GetHighestUid, it can blow up the application with an uncaught exception. Since those exceptions force your app to quit, you get a resiliency issue.
Here's a trival fix with an Action that can be used to catch most issues that can arise in the idle loop in order not to bring the house down.
The text was updated successfully, but these errors were encountered: