On Mar 27, 2010, at 17:34, Jon Robertson wrote:

> dZ:  Perfect understanding.  :)

The same happened to me a couple of years ago (as you point out in your 
previous post).  I couldn't fix it then and just made sure that I handle all 
errors in my OnDataAvailable handler.

> While the exception in #3 is the application's fault (my fault), I'm relying
> on OnBgException to be triggered if an exception occurs inside my
> OnDataAvailable event.  Either I shouldn't do this and ICS users should put
> their own exception handling inside OnDataAvailable, or ICS is broken.  :(

I must say that in truth, it's the application's problem:  TWSocket will 
continue to work normally, but your application is possibly in an invalid state.

That said, ICS *could* take care of it, otherwise you will never know that your 
application has a bug in the OnDataAvailable handler, just that weird stuff 
happens occasionally.

Since we have already seen that it is not such an easy fix (i.e. it's 
definitely not good to trigger OnBgException from the OnDataAvailable event), I 
will suggest that the best solution right now is to make sure OnDataAvailable 
handlers are wrapped inside a try/except block to catch *ALL* exceptions.

I will add this to the Wiki, and we should probably document it in the source 
too.

> wilfried:  The problem didn't surface until I changed ASyncReceive so that
> the exception occurring on my code (OnDataAvailable) was not swallowed by
> ASyncReceive.  I'm not calling Abort *after* the session is closed.  I don't
> think ICS is either, even with my changes.  But OnDataAvailable is fired a
> second time for the same data that was already being processed by my
> OnDataAvailable at the time my exception occurred.

TWSocket calls Abort from the OnBgException trigger if the handler sets the 
CanAbort to true.  The reality is that OnBgException is not meant to be called 
from ASyncReceive.

Either an entirely different event is triggered, or the execution flow needs to 
be changed somehow to avoid re-entry of the events.  Both solutions are 
non-trivial, so for now just make sure that your OnDataAvailable handler is 
wrapped in a try/except block.  Also, remove the OnBgException trigger from 
ASyncReceive, and you should be good.

        dZ.



-- 
        DZ-Jay [TeamICS]
        http://www.overbyte.be/eng/overbyte/teamics.html

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to