Sparkle server - life of server request


I have a couple of possibly related queries regarding my Sparkle server :

  1. My Sparkle server logs incoming requests in the ProcessRequest method, and then updates the log entry with the date/time completed at the end of the request, after the response has been sent to the client. Very occasionally (10 out of 50,000 requests), the log entry doesn't get updated with the date/time completed. Is it possible for a Sparkle request to fail to complete, if for example the client application 'killed' its connection? Or will the request always complete even if the client's connection is lost?

  2. Is it OK to read properties of the server context object (THttpServerContext) after calling Response.Close? I know I can't write to properties, but just wanted to check that reading is OK? For example :

C.Response.Close(TEncoding.UTF8.GetBytes('A plain text response.'));
intConnectionID := C.Request.User.Claims.Items['connection_id'].AsInteger;
intStatusCode := C.Response.StatusCode;
sStatusReason := C.Response.StatusReason;

Many thanks,

Hi Ian,

Yes: EHttpApiException -unknown- - #2 by wlandgraf.

Yes, it is.

Many thanks Wagner.

So I can add try..except around the Response.Close to handle the exception. Do I need to do anything else afterwards to ensure the thread is cleaned up and no memory/resources are leaked?


You should not need to protect Response.Close calls, unless you have a specific need for that. XData and Sparkle are very friendly libraries, in most cases you can simply let Sparkle handle it for you.