Skip to content

ConnectionManager check for idle connections is incorrect #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mzboray opened this issue May 15, 2017 · 1 comment · Fixed by #53
Closed

ConnectionManager check for idle connections is incorrect #52

mzboray opened this issue May 15, 2017 · 1 comment · Fixed by #53

Comments

@mzboray
Copy link
Contributor

mzboray commented May 15, 2017

We are running Papercut as a service. Once in a while we are seeing a failed send on the smtp client side when disposing our SmtpClient instance with the error:

System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpPooledStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.ForceCleanup()
at System.Net.ConnectionPoolManager.CleanupConnectionPool(ServicePoint servicePoint, String groupName)

The papercut log seems to indicate a connection was closed for being idle, but i'm not sure how we could have had it open for any great length of time:

2017-05-15 13:35:19.024 -07:00 [Information] Session timeout, disconnecting 32556

Looking at the logic, I believe the comparison check for idle connections in ConnectionManager is incorrect

// Loop through the connections
foreach (int key in keys)
{
	// If they have been idle for too long, disconnect them
	if (DateTime.Now < _connections[key].LastActivity.AddMinutes(20))
	{
		Logger.Information(
			"Session timeout, disconnecting {ConnectionId}",
			_connections[key].Id);
		_connections[key].Close();
	}
}

The comparison should be DateTime.Now > _connections[key].LastActivity.AddMinutes(20), i.e. close the connection if the current time is more than 20 minutes after the last activity. I can submit a pull request later on.

@mzboray
Copy link
Contributor Author

mzboray commented May 16, 2017

Fixed by #53.

@Jaben Jaben closed this as completed in #53 May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant