AwesomeSockets icon indicating copy to clipboard operation
AwesomeSockets copied to clipboard

TcpAccept Memory Leak

Open shockdot opened this issue 7 years ago • 3 comments
trafficstars

I just started checking out AwesomeSockets, so far so good.

One issue....

I'm attempting to make it so the Server can have multiple clients connected at once... To do that, it has to be constantly checking for new connections... I do that like this....

      private ServerClass()
      {
         ISocket listenSocket = AweSock.TcpListen(14804);

         // Create a new thread for listening for connections
         new Thread(() =>
            {
               while (true)
               {
                  ISocket socket = AweSock.TcpAccept(
                     listenSocket, 
                     SocketCommunicationTypes.NonBlocking, 
                     ConnectionCallBack);
               }
            }).Start();
      }

      private Socket ConnectionCallBack(ISocket socket, Exception exception)
      {
         // Do stuff...
         return socket.GetSocket();
      }

The issue is when I try to make it NonBlocking & use the callback, it seems to constantly grow in size (until an out of memory exception is thrown). Without the NonBlocking it works fine. Like so...

         new Thread(() =>
            {
               while (true)
               {
                  ISocket socket = AweSock.TcpAccept(
                     listenSocket);
                  if(socket != null)
                  {
                     ConnectionCallBack(socket, null);
                  }
               }
            }).Start();

shockdot avatar Dec 07 '17 07:12 shockdot

I fixed the issue, by changing....

new Thread(() => TcpAcceptThread(listenSocket, callback)).Start();

to...

         while (true)
         {
            TcpAcceptThread(listenSocket, callback);
         }

I think removed my own while loop when calling AweSock.TcpAccept (since it's now in the TcpAccept function.

shockdot avatar Dec 07 '17 08:12 shockdot

@shockdot Hmmm... Ill have to look into it...

nterry avatar Feb 20 '19 19:02 nterry

@shockdot Sorry for the huge hiatus. Are you still seeing this issue? I have released v2.1.15 on nuget. If still applicable, please try it out and tell me if you are still experiencing the same issue.

nterry avatar Jan 28 '20 04:01 nterry