RTC Forums

Subscription => Support => Topic started by: WilliamY on July 13, 2020, 11:07:03 PM

Title: TRtcHttpServer.StopListen issue
Post by: WilliamY on July 13, 2020, 11:07:03 PM

I was just finish upgradng my project to use the latest RealthinClient, Delphi 10.4 Sydney. I had the following codes in a window service OnStop event:

if RtcHttpServer.IsListening then

It took at least 10+ seconds to wait StopListen to be completed,   What was the procedure doing that would take such a long time??   I don't have such issue with v6.04 (the one I had upgraded from).

FYI,  There is no one connect to this window service,  I just did a start service, and then a stop service right after,  It took 10+ seconds to stop,  commented out above codes, everything then went to normal.



Title: Re: TRtcHttpServer.StopListen issue
Post by: Star5 on July 14, 2020, 05:27:23 AM

Title: Re: TRtcHttpServer.StopListen issue
Post by: D.Tkalcec (RTC) on July 14, 2020, 06:40:03 AM
If you are stopping your Server listener with the goal to terminate your Application, make sure to call "StopListenNow" (blocking, waits for the Server listener to actually stop before it continues to the next line of code) instead of "StopListen" (asynchronous, returns immediately, but requires expensive clean-up if the application starts terminating while the Server listener is still active).

"StopListenNow" was introduced in later RTC SDK versions to simplify the shut-down process and avoid all kinds of issues that could be caused by calling "StopListen" shortly before terminating the Application. In some cases, the Application would terminate immediately, while in other cases it would never terminate.

Due to the multi-threaded and event-driven nature of the RTC SDK, some things need to be taken care of before you start terminating your Application (for example, make sure the Server listener has actually been stopped and all the connections are closed with no background threads running), if you want to avoid problems during Application shut-down (like dead-locks, or thread synchronization issues, or asynchronous calls to events implemented on objects which have already been destroyed).

Title: Re: TRtcHttpServer.StopListen issue
Post by: WilliamY on July 14, 2020, 03:45:16 PM
Ah, Thanks for the clarification. Much appreciated.