Add SO_KEEPALIVE support for connection monitoring#43
Open
claudiodube wants to merge 2 commits into
Open
Conversation
- Enable TCP keepalive on server sockets to detect broken connections - Configure keepalive parameters: idle=60s, interval=300s, count=9 - Add debug logging for keepalive configuration - Follow existing setsockopt pattern after SO_LINGER configuration Implementation details: - Added #include <netinet/tcp.h> for TCP socket options - Enable SO_KEEPALIVE on all server sockets in server_socket() function - Configure TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT parameters - Use same error handling pattern as existing socket options Tested successfully: - Compilation: gcc builds without errors - Runtime: Debug log shows 'TCP keepalive enabled: idle=60s, interval=300s, count=9' - Functionality: curl test confirms connection redirection works properly - Compatibility: No breaking changes to existing functionality Benefits: - Automatic detection of broken connections after 46 minutes - Prevents resource leaks from stale connections - Improves reliability in production environments - Better behavior with firewalls and NAT devices
- Remove hardcoded TCP keepalive parameters (idle, interval, count) - Use system-wide sysctl settings instead of hardcoded values - Respects administrator's network configuration via: * net.ipv4.tcp_keepalive_time (currently 60s) * net.ipv4.tcp_keepalive_intvl (currently 300s) * net.ipv4.tcp_keepalive_probes (currently 9) - Follows Unix philosophy: one configuration location - More flexible and maintainable approach - Cleaner code with fewer magic numbers Tested: Debug log confirms 'TCP keepalive enabled using system defaults'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implementation details:
Tested successfully:
Benefits: