Skip to content

TcpEx: invalid TCP packet crashing a running server #40

Closed
@yallie

Description

@yallie

Got an strange issue on one of my client's servers.
The unhandled exception occurs on a thread pool I/O thread:

2018.02.13 15:14:00 Topshelf.Hosts.ConsoleRunHost: The service threw an unhandled exception
System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndAccept(Byte[]& buffer, Int32& bytesTransferred, IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.EndAccept(IAsyncResult asyncResult)
   at Zyan.Communication.Protocols.Tcp.DuplexChannel.Manager.listener_Accept(IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Manager.cs:line 241
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

Turns out to be an issue with some monitoring software.
The monitor seems to be pinging known addresses and immediately
closing the connection as long as it sees that the remote party is listening:

image

Seems that Zyan doesn't handle this situation properly (Manager.cs: line 241):

Socket client;
try
{
	client = listener.EndAccept(ar); // ** unhandled SocketException here**

	// Wait for next Client request
	listener.BeginAccept(new AsyncCallback(listener_Accept), new object[] { listener, channel });
}
catch (ObjectDisposedException ex)
{
	// the listener was closed
	Trace.WriteLine("TcpEx.Manager: the listener was closed. Got exception: " + ex.ToString());
	return;
}

The solution seems to be simply ignore the broken incoming connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions