Skip to content
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

Implement Keepalive Connection String Options #132

Closed
caleblloyd opened this issue Nov 3, 2016 · 3 comments
Closed

Implement Keepalive Connection String Options #132

caleblloyd opened this issue Nov 3, 2016 · 3 comments
Assignees
Milestone

Comments

@caleblloyd
Copy link
Contributor

@caleblloyd caleblloyd commented Nov 3, 2016

Keep Alive, Keepalive (default: 0) For TCP connections, idle connection time measured in seconds, before the first keepalive packet is sent. A value of 0 indicates that keepalive is not used.

Should call socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, value) on TCP Socket if value > 0

@caleblloyd
Copy link
Contributor Author

@caleblloyd caleblloyd commented Dec 6, 2016

Respecting System-Wide TCP Keepalive

Operating Systems (both Windoows and Linux) have default TCP Keepalive values, but TCP Keepalive must be enabled on the socket in order for Keepalive to be used. (Windows Reference, Linux Reference)

This setting is achieved by calling socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true)

Should we always enable TCP Keepalive on the Socket? Or only if the Keepalive connection string parameter is set? I'm partial to always enabling it due to the nature of pooled connections potentially being idle.

Overriding System-Wide settings with Per-Socket settings

There are 3 settings that can be overridden, outlined here. Example:

tcp_keepalive_time = 7200
tcp_keepalive_intvl = 75
tcp_keepalive_probes = 9

The first two parameters are expressed in seconds, and the last is the pure number. This means that the keepalive routines wait for two hours (7200 secs) before sending the first keepalive probe, and then resend it every 75 seconds. If no ACK response is received for nine consecutive times, the connection is marked as broken.

Overriding the system-wide parameters on Windows is described in this stackoverflow post

Overriding the system-wide parameters on Linux needs to be done with socket options, described here. I will have to dig into .NET's socket option ENUMs and see if these are defined

@caleblloyd caleblloyd self-assigned this Dec 6, 2016
@caleblloyd
Copy link
Contributor Author

@caleblloyd caleblloyd commented Dec 6, 2016

I can't get the socket-level options to work on Linux or OSX, the proper Socket Options are not available in .NET Core. Opened upstream:

https://github.com/dotnet/corefx/issues/14237

caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
caleblloyd added a commit to caleblloyd/MySqlConnector that referenced this issue Dec 7, 2016
@bgrainger
Copy link
Member

@bgrainger bgrainger commented Dec 7, 2016

Shipped in 0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants