|Subject:||Re: Feature request: processing of messages during TIdCustomTCPServer.TerminateAllThreads|
|Posted by:||Remy Lebeau \(Indy Team\) (firstname.lastname@example.org)|
|Date:||Fri, 23 Nov 2007|
"M." <Mitja.Perko.email@example.com> wrote in message
> I had a problem when request on server was waiting for some
> message before being able to complete it. If during that time
> (waiting for message) within the request TcpServer.Active was
> set to false it "freezed" up
Yes, that is a known deadlock. You can't perform synchronized operations in
your server's event handlers while shutting down the server, if the server
is running in the main thread. You can move the server to its own thread to
avoid that, though.
> since TerminateAllThreads does no message processing during
> waiting for all threads to end.
It can't without introducing other problems.
> So maybe something like TThread.WaitFor could be
> implemented instead of IndySleep(500)?
That would slow down the server's shutdown especially if a lot of clients
are connected, since the server would only be able to terminate the threads
one at a time, whereas right now it can terminate them all in parallel.
> I guess processing messages should have no bad influence on
> the rest of Indy
Not on Indy itself, but it can cause side-effects if used in the main thread
and the rest of your code is not protected from reentrant and other issues
related to manual message pumping.
> The listed todo also sounds very nice. Thumbs up for this :)
> // TODO: reimplement support for TerminateWaitTimeout
> This will be very good to prevent freezing.
Actually, no. That is not what TerminateWaitTimeout is for. In Indy 9,
TerminateWaitTimeout merely threw an exception if terminating the threads
took too long, which would leave the servers's internal thread list in an
unstable state. There was no message processing being done even when
TerminateWaitTime was still being used.
Feature request: processing of messages during TIdCustomTCPServer.TerminateAllThreads posted by M on Thu, 22 Nov 2007