Cook Computing

.NET Remoting Problem

September 26, 2005 Written by Charles Cook

I've spent some time recently investigating a .NET Remoting problem. On the system in question clients implement lease sponsorship. In some cases clients fail to unregister sponsors and so objects on the server are kept alive indefinitely, leading to system failure due to running out of virtual memory space. I thought I would implement some server-side code that would forcibly disconnect objects if they had not been called for a period of time, say one hour, using RemotingServices.Disconnect. If clients failed to unregister sponsors then this new code would ensure that leakage would only ever be up to one hours worth.

But this does not work. The following happens:

  • Client requests client activated object and registers a sponsor for it.
  • Client makes calls on object and then fails to unregister its sponsor.
  • After one hour server calls Disconnect for this object.
  • Client attempts call on object and it fails (as expected - "RemotingException - Requested Service not found").
  • But calls are still made to the sponsor and object not GC'ed
  • Object is only GC'ed when client process is killed.

I'm not sure yet whether this is a Remoting bug or whether I've misunderstood something. Things were so much easier with DCOM. No fiddling around with sponsors and when used in this type of scenario CoDisconnectObject worked just fine.