TidSmtpServer Stops responding - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Indy (https://www.atozed.com/forums/forum-8.html) +--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html) +--- Thread: TidSmtpServer Stops responding (/thread-807.html) |
TidSmtpServer Stops responding - bluewwol - 11-09-2018 Hi, I have TidSmtpServer setup and running, it runs fine for a period of time, then stops responding. When I set the server active := True it creates 2 threads for each IP binding I have made. Each of these IP's do for a period of time handle incomming requests as expected. Then slowly each IP stops responding to external requests and the 2 threads created when the server was set to active appear to terminate. The bindings all are still set, and restarting to server (Active set to False then True) does not solve the problem. I presume that since it is the Listener Threads that are failing we should expect to see the onListenException be fired when that occurs, however I never see this get called. Code: procedure TdSmtpServ.WwolSmtpServListenException(AThread: TIdListenerThread; AException: Exception); Code: procedure TdSmtpServ.SetBoundIp(ServerId: integer); Code: with WwolSmtpServ do Any pointers on where to look would be most welcome -Allen RE: TidSmtpServer Stops responding - bluewwol - 11-09-2018 This seems to belong to the self inflicted injury type. I have made 2 changes in my app that seem to have made a positive impact (although only in test for about an hour, where previously stability issues were occuring within that timeframe). The addition of a try except block in my onConnect event Code: procedure TdSmtpServ.WwolSmtpServConnect(AContext: TIdContext); and removed the TmySmtpItem(AThread.Data).LastEvent := 'WwolSmtpServListenException ' + AException.ClassName + ' - ' + AException.message; statement from the onListenException event. One or both of these appear to have made a positive impact. I presume it must be the later as that impacts the Listener threads. -Allen RE: TidSmtpServer Stops responding - rlebeau - 11-09-2018 (11-09-2018, 06:35 PM)bluewwol Wrote: The addition of a try except block in my onConnect event If an exception occurs in the OnConnect event, you are logging it, but then you are discarding it. Don't do that. Re-raise the exception and let the server handle it so the client can be disconnected. Alternatively, get rid of the try...except altogether, and do your error logging in the OnException event instead, which is triggered whenever an uncaught exception occurs in a client thread. BTW, Indy has a TIdThreadSafeInteger class (and Int64 and Cardinal variants) in the IdThreadSafe unit. You could replace your unique_id variables with that class, and then get rid of SenderCS. (11-09-2018, 06:35 PM)bluewwol Wrote: and removed the In the OnListenException event, the AThread.Data property is nil (unless you assign your own Data object in the OnBeforeListenerRun event). That event is triggered whenever an uncaught exception occurs in a listener thread, not in a client thread. Your TmySmtpItem objects are not assigned to listener threads, they are assigned to client contexts own by client threads. So, in the OnListenerException event, AThread.Data will NEVER point to a TmySmtItem object, and as such TmySmtpItem(AThread.Data).Id and TmySmtpItem(AThread.Data).Id are invalid. Now, why the OnListenException event would be triggered at all, is a different matter that you still need to debug. Just fix your logging to not access invalid data fields. RE: TidSmtpServer Stops responding - bluewwol - 11-10-2018 (11-09-2018, 08:42 PM)rlebeau Wrote: Now, why the OnListenException event would be triggered at all, is a different matter that you still need to debug. Just fix your logging to not access invalid data fields. Remy; The OnListenException is still being triggered fairly frequently, however with the try .. excepts removed Indy handles the problem and keeps on ticking. So my app is now functional over time now. As to the cause of the exceptions, I will let it run over the weekend and review on Monday, however a comonality on all of these exceptions is that have occured this afternoon is that Indy shows the AThread.Binding.PeerIP to be ''. In my judgement this appears to be a consequence of questionable probing of the IP?? right now I am logging this, no longer interfering with Indy handling the exception and the world continues function as expected. As I learn more on Monday I will provide feedback, Thanks again for your assistance, -Allen RE: TidSmtpServer Stops responding - rlebeau - 11-12-2018 (11-10-2018, 12:30 AM)bluewwol Wrote: The OnListenException is still being triggered fairly frequently, however with the try .. excepts removed Indy handles the problem and keeps on ticking. So my app is now functional over time now. It wasn't just about removing try..except blocks, but about fixing your code to stop accessing things in the incorrect way. (11-10-2018, 12:30 AM)bluewwol Wrote: As to the cause of the exceptions, I will let it run over the weekend and review on Monday, however a comonality on all of these exceptions is that have occured this afternoon is that Indy shows the AThread.Binding.PeerIP to be ''. In my judgement this appears to be a consequence of questionable probing of the IP?? Again, you are mixing up LISTEN threads with CLIENT threads. They are TWO DIFFERENT THINGS. A listen thread accepts a client on a listening port and spawns a NEW THREAD to manage that client, then goes back to accept the next client on the port. So, there is no Peer on a LISTEN thread, so of course AThread.Binding.PeerIP will always be blank, as AThread.Binding represents a listening socket, not a client socket. (11-10-2018, 12:30 AM)bluewwol Wrote: right now I am logging this, no longer interfering with Indy handling the exception and the world continues function as expected. Maybe try something more like this: Code: // OnException event handler |