WebSocketListener icon indicating copy to clipboard operation
WebSocketListener copied to clipboard

Server stops accepting connections after 2 days

Open awb99 opened this issue 7 years ago • 2 comments

I run Websocket server on debian Linux with mono. A few days after starting the server it no longer accepts new connections from Clients. Any clues as to why this could be?

void StartAcceptingConnections ()
        {
	        var myContext = Context;
		   Task.Factory.StartNew( async () =>
		   {

			   logger.Info("StartAcceptingConnections..");
			   while (running)
			   {
				   vtortola.WebSockets.WebSocket client = await server.AcceptWebSocketAsync(cancellationToken);

				   try
				   {
					   logger.Info($"WebSocket Connection has been accepted! RemoteEndpoint: {client.RemoteEndpoint}");
					   IActorRef connectionActor = myContext.ActorOf(Props.Create(() => new WebSocketPusherClientConnection(tradingSystem, client)), "PusherClient-" + Guid.NewGuid().ToString() );


				   }
				   catch (Exception ex)
				   {
					   logger.Error($"WebSocket Connection acceptance exception for RemoteEndpoint: {client.RemoteEndpoint}. ex: {ex.Message} {ex.StackTrace} ");
				   }
			   }

		   });
        }

awb99 avatar Dec 09 '17 12:12 awb99

It is hard to know just by looking at the code. How do you know that is not accepting connections? Do you see anything in the logs ? You may want to put the AcceptWebSocketAsync inside the try/catch

vtortola avatar Dec 09 '17 16:12 vtortola

@vtortola I am connecting to the Websocket server.. And get 'connection established' messages first. After a few days I cannot connect anymore. Thanks for the tip to move the accept inside the try catch. This might really be the solution.. Who knows perhaps something does fire an exception at that point. I guess I was too blind to see this possible option. Will revert in 3 days :-)

awb99 avatar Dec 09 '17 16:12 awb99