Memory Leak due to Exception in End Invoke RRS feed

  • Question

  • Hi,

    I am using .Net Remoting for sending objects between two servers.

    The objects are sent by "Begin Invoke" mechanism, as required in such case I use EndInvoke, but the following exception consistently thrown during the End Invoke:

    System.Net.WebExceptionSystem.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond …

       at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)

       at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

       --- End of inner exception stack trace ---

    Server stack trace:

       at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)

       at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)

       at System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.AsyncHttpClientRequestState.ProcessGetRequestStreamCompletion(IAsyncResult iar)

    Exception rethrown at [0]:

       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

       at Core.Common.CLSAPI.EventArrivedHandler.EndInvoke(IAsyncResult result)

    After some hours my application crashes due to "Out Of Memory Exception" and from the dump file I can see that all the objects that I tried to send still be referenced by one of the remoting objects therefore still not collected by the GC.

    What is the right way to handle exception in EndInvoke to avoid memory leak?

    I understand that this problem might be caused/fixed by some changes on the client side, nevertheless it is important for me to understand which changes can I do on the server side to assure robustness of my server.

    Thanks in advance


    Sunday, November 4, 2012 11:39 AM