API to kill keep-alive sessions
Development toolkit for Web Services and XML data bindings for C & C++
Brought to you by:
engelen
When my server is instructed to shut down, it is trying to cleanly terminate all SOAP connections from clients. The problem is that with HTTP keep-alive soap_serve() can block its thread for several minutes. I am currently trying to terminate it by calling closesocket(soap->socket) asynchronously from another thread. I am not sure whether this is correct solution especially considering compression and encryption layers. It would be much better to make soap_destroy/soap_end or some other function perform proper asynchronous termination of keep-alive sessions.
Logged In: YES
user_id=354274
Originator: NO
Each iteration through the server loop after a request was served and before the nest is calls the soap->fserveloop callback, which you can use to manipulate soap->keep_alive, e.g. using a timer. Setting soap->keep_alive to 0 will terminate the loop.
To asynchronously terminate the loop is tricky, since you don't know for sure if a request just arrived and is being processed. Similarly to closing the socket: the request may have been received and the thread is about to respond over the socket.
Logged In: YES
user_id=1312539
Originator: NO
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Logged In: YES
user_id=1882568
Originator: YES
The solution you recommend doesn't work. Function soap_serve blocks inside call to soap_begin_recv(). It block there in select() system call for the specified timeout which is high with keep-alive sessions. Callback soap->fserveloop is checked only after the timeout is reached.
The only case soap->fserveloop is checked happens when the client using the keep-alive session makes random SOAP call after my server was asked to shut down. In this case this extra request is served, soap->fserveloop is called and server shuts down. However, it is not possible to expect all clients hanging on keep-alive sessions to perform some request when my server is about to shut down.
For now, I continue to use the asynchronous closesocket() call to kill all keep-alive sessions. I am still in favor of having some API for asynchronous termination of keep-alive sessions that would take care of compression and encryption.