This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.