1. Does the Routing Provider create any other TRtcHttpClient components on-demand?
No, i'm absolutely sure.
2. Is the Routing Provider accessing anything that it hasn't created (not the owner)? Maybe even something created outside of the unit?
No, it does not even have a DataModuleCreate handler. It does use HaveSession, FindSession and UnlockSession though.
3. The fact that the Routing Provider is being destroyed from the unit Finalization section could mean that some things required by the Routing Provider have already been destroyed before reaching the finalization section of that unit. If the Routing Provider is used in a Windows Service **CUT**
It is used in a setup very similar to the webserver demo. It is extremely convenient to start the exe as an application when setting parameters (database, ports et.al.) and test and then terminate the application and start the service. When running as a service sometimes i have to kill the process. Running as an application the problem is more reproduceable (and debuggable) of course.
So, i create a new global procedure in parallel with "GetRoutingProvider" called "FreeRoutingProvider" and call that in the "Stop" method that gets called from the service on shutdown and from the application btnStopListening. This seems to make things better. It is, however awkward to "break" the general layout of it all.
But, now that i put some more XLog's into it all i can see the following, and this might be my problem. This code:
if lSettings.Port <> 0 then
begin
XLog('Stopping HTTP Server...');
ServerHTTP.StopListenNow;
while (ServerHTTP.isListening) or (ServerHTTP.TotalServerConnectionCount > 0) do
Sleep(250);
XLog('Finished HTTP Server...');
end;
if lSettings.SSLPort <> 0 then
begin
XLog('Stopping HTTPS Server...');
ServerHTTPS.StopListenNow;
while (ServerHTTPS.isListening) or (ServerHTTPS.TotalServerConnectionCount > 0) do
Sleep(250);
XLog('Finished HTTPS Server...');
end;
that gets executed before cleaining and stopping. Produces the following log result:
2014-10-26 12:05:25.178; SERVER ServerHTTP STARTED on Port 80...
2014-10-26 12:05:25.459; SERVER ServerHTTPS STARTED on Port 443...
2014-10-26 12:06:11.446; Stopping HTTP Server...
2014-10-26 12:06:11.478; SERVER ServerHTTP STOPPED.
2014-10-26 12:06:11.531; Finished stopping HTTP Server...
2014-10-26 12:06:11.539; Stopping HTTPS Server...
2014-10-26 12:06:11.594; Finished stopping HTTPS Server...
2014-10-26 12:06:11.644; Disconnecting clients...
2014-10-26 12:06:11.646; Waiting for 0 client connections to close...
2014-10-26 12:06:12.148; Cleaning router queues...
2014-10-26 12:06:12.207; SERVER ServerHTTPS STOPPED.
the "SERVER ServerHTTPS STOPPED" line should be printed before the "Finished stopping HTTPS Server..."! The lines "SERVER %s STOPPED." are printed in the ServerHTTPListenStop event connected to both servers in the server module. The three lines before the last bold line is from the routing providers CloseClients.
I really must apologize for not seeing this before now, my bad definitely
.
Perhaps i need some other way of waiting for the HTTPS server to stop?