locked
Thread started by WCF got stopped in IIS worker process recycling RRS feed

  • Question

  • Hi,

    I have a WCF service hosted in IIS 7.0 using WAS (tcp listener). Inside the WCF service,I am accessing an external web service using a threadpool thread . Once I made a request to the external service, I need to check periodically whether that request is completed or not by accessing some other methods exposed by the external web service , for that, I have created a timer and I call the web service method  according to the timer till my request get completed (the final status of the original request will be either Done or Error). But some times the request takes some time to complete , and I noticed that some times, the request never get to the final state(done/error) . When I checked, Iunderstood that the thread in which the periodic check made (thread created by timer) is not active , the reason behind is the IIS application pool worker process got recycled .

    How can I avoid this ? the threads which access the service initially can happen at any time(this is based on when the user of the application make a request) and after the initial request I need to check periodically the status of the request till it is in one of the final state(done/error), but if the worker process get recycled ,once I made the initial request and start the peridic checks , my request will never get comleted . Can I handle it within IIS itself ?
    Or do I need to have some other way of handling this ?

    .net
    Thursday, January 14, 2010 5:41 AM

Answers

  • Hi Jeressh,

    When app pool are recycling, the ServiceHost.Closing event will fire. This could be a point to save the client data. However, there are some other reason could casue wcf shutdown such as app exception, you need take into account of these conditions.

    Thanks,
    Mog Liang
    • Marked as answer by Mog Liang Thursday, January 21, 2010 9:30 AM
    Tuesday, January 19, 2010 1:53 AM

All replies


  • Do your clients wait in a blocking call to your service for the request result (done/error) or do you use a singleton with a polling mechanism ?
    If they use a blocking call there is not much you can do beside disabling worker  process recycling.

    If they use a polling mechanism than you can design your service to store state data (e.g. list of  requests to check ) out of process (e.g. data base) so that it survives a wp recycle.
    Sunday, January 17, 2010 3:46 AM
  • Hi ,

    My external service clients are not blocking, any way I understood that when worker process get recycled all my data will be lost including static variables data , I am thinking of implementing a state maintaining mechanism such that my data will be stored and restored when recycle happens.
    in case of querying the external web service I can host the service in a windows service but i have some other service which maintain a pool of objects where each object corresponds to a particular client . the clients are directly connected to a server(using TCP connection) which expose itself publicly and from this server I am connecting to my App server where business logic exists , so whenever my  public server connected to a client it sends the data to my app server using a WCF service , and the client may exchange some data and I  need to process the data using my App server , the data from the client may come in multiple chunks and i can only identify the end of data using my application logic hence i need to keep each chunk of data from  clients in my app server till  i have done with the client , Hence i am using some kind of an object pool at the app server where each object corresponds to a particular client. but when app pool recycle happens my stored data for clients may lost  and i may not have done with a client. i cant access db to store  each and every  data chunk from client ( will cause a lot of DB hits ie why i keep it in memory in object pool). Hence I am thinking of serializing the object pool when app recycle happens and restore it when new worker process starts. I thought of using the factory to create my Service Host (like TradeServiceCustomHostFactory : ServiceHostFactory from http://msdn.microsoft.com/en-us/library/bb332338.aspx) hook the opening and closing events of the service host to serialize and deserilaise my object pool . My question here is to whether my understaing is right or not , ie , the openning and closing of the service host will fire each time when the apppool recycle  isn't , please correct me If I am wrong

    Cheers,
    Jereesh







    .net
    Monday, January 18, 2010 7:19 AM
  • Hi Jeressh,

    When app pool are recycling, the ServiceHost.Closing event will fire. This could be a point to save the client data. However, there are some other reason could casue wcf shutdown such as app exception, you need take into account of these conditions.

    Thanks,
    Mog Liang
    • Marked as answer by Mog Liang Thursday, January 21, 2010 9:30 AM
    Tuesday, January 19, 2010 1:53 AM