This is a short one. I encountered a weird problem that had me stumped for a few minutes this afternoon. I'm registering an instance of a MarshalByRefObject object in my application with the remoting infrastructure so that I can use it from another process on the same system. Everything worked fine, so I went for a cup of coffee and a chat with some collegues; must have been gone about 10 minutes. When I got back, I performed an operation on my client application and got a SocketException. I checked that my remoting host was still running and hadn't thrown any exceptions, and all was fine there.
It transpired, after some soul searching, that my lease was expiring on the remote service object I was registering with RemotingServices.Marshal(...) so my client was getting a SocketException because the service was no longer available. My service object was being set up for garbage collection by the remoting framework.
By default a remote objects lease is set to 5 minutes. To control the lease for all remote objects in an AppDomain you can use the System.Runtime.Remoting.Lifetime.LifetimeServices class to configure a new initial lifespan value and control other lifetime settings (such as how much time to add to an object's lifetime after it receives a message).
That would be a neat solution, but I didn't want to extend the initial lifetime of remote objects for the entire AppDomain, so I overrode the InitializeLifetimeServices() method so that it modified the base classes lease initial lifetime to 24 hours, and it's RenewOnCallTime to an hour. This would increase the objects lifetime by an hour everytime it received a message.
Another way I could have done this would be to register a custom sponsor object with the lease, so that when the lease was about to expire, the sponsor would renew it. That was too much work :-)
Laterz.
It transpired, after some soul searching, that my lease was expiring on the remote service object I was registering with RemotingServices.Marshal(...) so my client was getting a SocketException because the service was no longer available. My service object was being set up for garbage collection by the remoting framework.
By default a remote objects lease is set to 5 minutes. To control the lease for all remote objects in an AppDomain you can use the System.Runtime.Remoting.Lifetime.LifetimeServices class to configure a new initial lifespan value and control other lifetime settings (such as how much time to add to an object's lifetime after it receives a message).
That would be a neat solution, but I didn't want to extend the initial lifetime of remote objects for the entire AppDomain, so I overrode the InitializeLifetimeServices() method so that it modified the base classes lease initial lifetime to 24 hours, and it's RenewOnCallTime to an hour. This would increase the objects lifetime by an hour everytime it received a message.
Another way I could have done this would be to register a custom sponsor object with the lease, so that when the lease was about to expire, the sponsor would renew it. That was too much work :-)
Laterz.
Comments