Home Bug Reports

C# TCP memory leak occur

laurialauria Member Taiyoung JangOrganization: wemade creative Co., Ltd.Project: server develop
hi,
i tried massive connecting to C# ice server socket examples.
i found memory increasing.

i think some change need.

Ice/TcpTransceiver.cs

public void close()
{
try
{
_fd.Close(0); // TIME_WAIT
#if ICE_SOCKET_ASYNC_API
_readEventArgs.Dispose();
_writeEventArgs.Dispose();
#endif
}
catch(SocketException ex)
{
throw new Ice.SocketException(ex);
}
finally
{
_fd = null;
#if ICE_SOCKET_ASYNC_API
_readEventArgs = null;
_writeEventArgs = null;
#endif
_readCallback = null;
_writeCallback = null;
}
}

#if ICE_SOCKET_ASYNC_API
internal void ioCompleted(object sender, SocketAsyncEventArgs e)
{
try
{
switch (e.LastOperation)
{
case SocketAsyncOperation.Receive:
_readCallback(e.UserToken); // if _readCallback is null
break;
case SocketAsyncOperation.Send:
case SocketAsyncOperation.Connect:
_writeCallback(e.UserToken); // if _writeCallback is null
break;
default:
throw new ArgumentException("The last operation completed on the socket was not a receive or send");
}
}catch(Exception ex)
{
_logger.trace(_traceLevels.networkCat, ex.ToString());
}
}
#else

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    Thanks for the report, we'll look into fixing this.

    Cheers,
    Benoit.
  • robert.vazanrobert.vazan Member Robert VazanOrganization: WBP onlineProject: Financial news delivery network
    Ping. I think this bug is more serious than it appears at first glance.

    Connection is leaked every time some connection attempt throws ConnectionRefusedException as is common with explicitly registered well-known objects on developer machines. Any application that tries to reconnect periodically to such dead endpoints will keep leaking memory continuously.

    Our servers ping every failed proxy every 10 seconds. I just checked memory dump from one of our servers. In just 3 days, it accumulated 120,000 leaked connections equaling 1GB of leaked RAM. Our servers currently consume 1-2GB RAM each despite periodic restarts.
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Robert,

    We will address this issue in the next Ice release. In the meantime, a work-around could be to avoid pinging these failed proxies so often. If this is not practical and you can't wait for the next Ice release, you could subscribe to our Priority Support and a request a patch.

    Best regards,
    Bernard
  • AntonAnton Member Anton TarasevichOrganization: SOFTEQProject: Distributed data processing.
    A month ago I faced with leak problem. In my case it was many OVERLAPPEDDATA pinned objects.

    Downloaded ZeroC's Ice sources and analizied them.I've found
    that asyncsocket event arg is never been disposed

    File:
    TCPtransceiver.cs

    members:
    private SocketAsyncEventArgs _writeEventArgs;
    private SocketAsyncEventArgs _readEventArgs;


    They are properly initialized and used but On close() they are NOT disposed

    Full description is here

    SocketAsyncEventArgs leaks its memory unless manually disposed | Microsoft Connect

    I've already sent a letter to ZeroC with proposed fix in the source code.
  • sylvainsylvain Member Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systems ✭✭
    Great, thanks!

    I am eagerly waiting for a fix, sounds not that difficult ;-)

    Regards.
  • sylvainsylvain Member Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systems ✭✭
    Hello ZeroC Team!

    Just wondering: is a fix coming?

    Thanks in advance,

    Best regards.
  • sylvainsylvain Member Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systems ✭✭
    Does ICE 3.6 fix this?

    Hi ZeroC team,

    Does the latest 3.6 address the issue described in this thread?

    Thanks in advance for your reply.
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    Yes, this should be fixed with Ice 3.6.0.

    Cheers,
    Benoit.
Sign In or Register to comment.