Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

TCP Keepalive Support #376

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

shawnstephens
Copy link

I've ported TCP Keepalive support from the redis-rb client. Quite often firewalls exist between the mongo client and the server. These firewalls aren't always configured to perform a proper fin/ack sequence when closing idle connections. This causes moped and other TCP based client to simply hang on the next request until the underlying operating system determines the connection has been closed.

Linux has support for TCP keepalives on sockets. My implementation ensures that the appropriate methods are only created if supported by the platform. If not supported, an alternate method is created with a simple log statement to let the user know Keepalives won't be available on that platform. Conditional method creation ensures performance by not having to check for the constants on every connection calls.

I'd like to give this code back to mongoid/moped to help make the socket connections more resilient.

@ElMassimo
Copy link

Does moped provide any of the alternatives mentioned here to handle timeouts in idle connections?

@shawnstephens
Copy link
Author

@ElMassimo Moped doesn't implement keep alive for like the article recommend, which is what my merge enables. Moped also to my knowledge doesn't support MaxIdleConnectionTimeout and has no connection reaping like the C# driver.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants