Re: [twsocket] Exceptions ignored in OnDataAvailable method
On Mar 25, 2010, at 18:33, Jon Robertson wrote: Does anyone know why ASyncReceive is swallowing the exception and not calling HandleBackgroundException? Wow, that was a some time ago. As far as I recall, Arno and I verified that it was indeed a bug; the code should be trapping exceptions and calling HandleBackgroundException() when they occur. I believe it was just never patched. I saw that we left the discussion by Arno recommending that Francois take a look at it. My guess is that he hasn't had a chance yet. Francois, is there any objection to patching ASyncReceive to call the BG Exception handler? 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
Re: [twsocket] Exceptions ignored in OnDataAvailable method
Francois, is there any objection to patching ASyncReceive to call the BG Exception handler? No objection. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be - Original Message - From: DZ-Jay d...@caribe.net To: ICS support mailing twsocket@elists.org Sent: Friday, March 26, 2010 10:14 AM Subject: Re: [twsocket] Exceptions ignored in OnDataAvailable method On Mar 25, 2010, at 18:33, Jon Robertson wrote: Does anyone know why ASyncReceive is swallowing the exception and not calling HandleBackgroundException? Wow, that was a some time ago. As far as I recall, Arno and I verified that it was indeed a bug; the code should be trapping exceptions and calling HandleBackgroundException() when they occur. I believe it was just never patched. I saw that we left the discussion by Arno recommending that Francois take a look at it. My guess is that he hasn't had a chance yet. Francois, is there any objection to patching ASyncReceive to call the BG Exception handler? 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 -- 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
Re: [twsocket] Exceptions ignored in OnDataAvailable method
Jon Robertson wrote: FWIW, I've patched the exception handler in ASyncReceive as below. If there are objections, please explain them so I can determine another solution. except on E:Exception do begin bMore := FALSE; HandleBackGroundException(E); end; end; Seems fine. That's probably what I was going to do. One thing to note is that applications that currently depend on Abort not being called here will need to implement OnBgException and set CanAbort to False. That is true. And I just noticed one more thing: If OnBgException is not assigned (or if the handler generates an exception), the exception will propagate all the way to TCustomWSocket.WndProc(), which will call.. HandleBackGroundException(E) again! Since what we want is to give the application a chance to handle the error whenever the TriggerOnDataAvailable call raises an exception, it may be better to catch that particular event and treat it specially. I'll have to think about this one to come up with a better solution. dZ. -- 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
Re: [twsocket] Exceptions ignored in OnDataAvailable method
My service, which communicates using ICS, is flakey for some customers. I've got quite a bit of exception handling and logging, and there was nothing indicating an exception was occurring. I finally pinpointed an exception that one customer was getting. I hooked TWSocket.OnDataAvailable and was doing custom processing, and the exception occurred in my code. However, the OnBgException event never fired. ASyncReceive is swallowing my exception. I searched my twsocket list archive, and found the message below from two years ago. Then I checked the latest sources in SVN and found that this code has not changed. Does anyone know why ASyncReceive is swallowing the exception and not calling HandleBackgroundException? Thanks! On Sun, Dec 2, 2007 at 2:20 AM, Arno Garrels arno.garr...@gmx.de wrote: DZ-Jay wrote: On Dec 1, 2007, at 13:36, Arno Garrels wrote: Have you got any exception that was raised from TWSocket internaly? I mean outside of your handler? Well, I noticed the issue because my handler raised an unhandled exception and the application then behaved in a strange manner because it was never caught (just absorbed by ASyncReceive). Yes, I noticed that yesterday as well when I was debugging a client pool. I got an error on ReallocMem() in TriggerDataAvailable in TCustomLineWSocket, the the destructor was called and raised an EInvalidPointer on FreeMem(), most likely due to the attempt to access and free an already freed object (most likely my fault in this case) but it took me several hours yesterday to find the problem since clients just disapeared silently unless I ran the server in the debugger. But then looking deeper, I found that at least SmtpProt and FtpProt *can* raise exceptions in the WSocketDataAvailable event (not that they have). In particular, the obvious exception they raise is if the FNext pointer is NULL and its processing ExecAsync. Admittedly that should never happen, but ignoring it is just asking for trouble (which is why I think Francois added the check and the exception there). Also, the buffer manipulations performed there could theoretically fail, and an exception would not be caught, yet the component would be in a strange state. Yes, for instance ReallocMem() may raise EOutOfMemory, got this twice yesterday while stressing a server application with thousands of connections. Perhaps wrapping those handlers in a try..except block would be better. It's something Francois should have a look at when he has some time. -- Arno Garrels -- 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 -- 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
Re: [twsocket] Exceptions ignored in OnDataAvailable method
DZ-Jay wrote: On Dec 1, 2007, at 13:36, Arno Garrels wrote: Have you got any exception that was raised from TWSocket internaly? I mean outside of your handler? Well, I noticed the issue because my handler raised an unhandled exception and the application then behaved in a strange manner because it was never caught (just absorbed by ASyncReceive). Yes, I noticed that yesterday as well when I was debugging a client pool. I got an error on ReallocMem() in TriggerDataAvailable in TCustomLineWSocket, the the destructor was called and raised an EInvalidPointer on FreeMem(), most likely due to the attempt to access and free an already freed object (most likely my fault in this case) but it took me several hours yesterday to find the problem since clients just disapeared silently unless I ran the server in the debugger. But then looking deeper, I found that at least SmtpProt and FtpProt *can* raise exceptions in the WSocketDataAvailable event (not that they have). In particular, the obvious exception they raise is if the FNext pointer is NULL and its processing ExecAsync. Admittedly that should never happen, but ignoring it is just asking for trouble (which is why I think Francois added the check and the exception there). Also, the buffer manipulations performed there could theoretically fail, and an exception would not be caught, yet the component would be in a strange state. Yes, for instance ReallocMem() may raise EOutOfMemory, got this twice yesterday while stressing a server application with thousands of connections. Perhaps wrapping those handlers in a try..except block would be better. It's something Francois should have a look at when he has some time. -- Arno Garrels -- 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
Re: [twsocket] Exceptions ignored in OnDataAvailable method
DZ-Jay wrote: Hello: In the TWSocket component, I've noticed that if an exception is thrown within an OnDataAvailable handler (which is triggered from TCustomWSocket.ASyncReceive() method) they will be ignored, and only the bMore flag is set to false which will stop the receive loop. Have you got any exception that was raised from TWSocket internaly? I mean outside of your handler? -- Arno Garrels -- 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
Re: [twsocket] Exceptions ignored in OnDataAvailable method
On Dec 1, 2007, at 13:36, Arno Garrels wrote: Have you got any exception that was raised from TWSocket internaly? I mean outside of your handler? Well, I noticed the issue because my handler raised an unhandled exception and the application then behaved in a strange manner because it was never caught (just absorbed by ASyncReceive). But then looking deeper, I found that at least SmtpProt and FtpProt *can* raise exceptions in the WSocketDataAvailable event (not that they have). In particular, the obvious exception they raise is if the FNext pointer is NULL and its processing ExecAsync. Admittedly that should never happen, but ignoring it is just asking for trouble (which is why I think Francois added the check and the exception there). Also, the buffer manipulations performed there could theoretically fail, and an exception would not be caught, yet the component would be in a strange state. Perhaps wrapping those handlers in a try..except block would be better. 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