Socket handles/connections lingering?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J. Dudgeon

    #1

    Socket handles/connections lingering?

    Hello,

    I've written a server that acts as a proxy between the PC and the mainframe
    worlds. This server service is writting in C# w/.NET 1.1. The service is
    TCP/IP based and makes heavy use of sockets.

    The "client" to the service is a C# class library that also uses sockets.
    I've managed to get the performance of the service up to a decent speed but
    I've hit a strange problem.

    My test program (that uses the C# class library) runs a series of
    transactions on multiple threads for a configurable number of iterations.
    Everything runs fine up until around 3600-3900 transactions (total) at which
    point my C# class library throws a SocketException from the Socket.Connect
    call:

    System.Net.Sock ets.SocketExcep tion: Only one usage of each socket address
    (protocol/network address/port) is normally permitted.

    I understand what this message is saying but I don't know why I'm getting
    it. The C# class library guarantees, in its Dispose() method that
    Socket.Close() is called (to free the underlying socket handle.) The test
    program wraps the C# class in a "using" block to ensure the Dispose() method
    is called on my C# class (which inherits from IDisposable.) I even tried
    setting the DontLinger option to true but the problem remains. Doing a
    "NETSTAT -a" in the console shows numerous TCP/IP connections from the test
    program to the service with a TIME_WAIT status; so, apparently all the
    sockets are being consumed and not released fast enough.

    If I terminate the process (or even wait a while) I can run another 3600
    transactions before getting this error. The problem with this is that I can
    reach 3600 transactions in about 1 minute.

    Is what I'm seeing a bug in System.dll library? Peeking into the source
    shows that the Socket class calls OSSOCK.closesoc ket in its Dispose()
    method, so I'm not sure why things aren't getting closed. Eventually the
    socket handles are freed but it seems to take just long enough to cause
    issues.

    Is there a socket option that I can set to alleviate this issue? Can
    Windows just not keep up with freeing the socket handles?

    Any help would be greatly appreciated.

    Thank you in advance,

    Joel


  • J. Dudgeon

    #2
    Re: Socket handles/connections lingering?

    Bah sorry, wrong forum, well unless someone knows. :)

    "J. Dudgeon" <j-nospam-oel.dudgeon@ca. unisys.com> wrote in message
    news:O6mEpbMrDH A.2772@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hello,
    >
    > I've written a server that acts as a proxy between the PC and the[/color]
    mainframe[color=blue]
    > worlds. This server service is writting in C# w/.NET 1.1. The service is
    > TCP/IP based and makes heavy use of sockets.
    >
    > The "client" to the service is a C# class library that also uses sockets.
    > I've managed to get the performance of the service up to a decent speed[/color]
    but[color=blue]
    > I've hit a strange problem.
    >
    > My test program (that uses the C# class library) runs a series of
    > transactions on multiple threads for a configurable number of iterations.
    > Everything runs fine up until around 3600-3900 transactions (total) at[/color]
    which[color=blue]
    > point my C# class library throws a SocketException from the Socket.Connect
    > call:
    >
    > System.Net.Sock ets.SocketExcep tion: Only one usage of each socket address
    > (protocol/network address/port) is normally permitted.
    >
    > I understand what this message is saying but I don't know why I'm getting
    > it. The C# class library guarantees, in its Dispose() method that
    > Socket.Close() is called (to free the underlying socket handle.) The test
    > program wraps the C# class in a "using" block to ensure the Dispose()[/color]
    method[color=blue]
    > is called on my C# class (which inherits from IDisposable.) I even tried
    > setting the DontLinger option to true but the problem remains. Doing a
    > "NETSTAT -a" in the console shows numerous TCP/IP connections from the[/color]
    test[color=blue]
    > program to the service with a TIME_WAIT status; so, apparently all the
    > sockets are being consumed and not released fast enough.
    >
    > If I terminate the process (or even wait a while) I can run another 3600
    > transactions before getting this error. The problem with this is that I[/color]
    can[color=blue]
    > reach 3600 transactions in about 1 minute.
    >
    > Is what I'm seeing a bug in System.dll library? Peeking into the source
    > shows that the Socket class calls OSSOCK.closesoc ket in its Dispose()
    > method, so I'm not sure why things aren't getting closed. Eventually the
    > socket handles are freed but it seems to take just long enough to cause
    > issues.
    >
    > Is there a socket option that I can set to alleviate this issue? Can
    > Windows just not keep up with freeing the socket handles?
    >
    > Any help would be greatly appreciated.
    >
    > Thank you in advance,
    >
    > Joel
    >
    >[/color]


    Comment

    Working...