Add TCP keepalive options for database connections - #4748
Open
tsg wants to merge 2 commits into
Open
Conversation
✅ Deploy Preview for electric-next ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
This adds the following config options. These are set on the underlying TCP socket.
ELECTRIC_DATABASE_TCP_KEEPALIVE_IDLE- Idle time before probing. EnablesSO_KEEPALIVEELECTRIC_DATABASE_TCP_KEEPALIVE_INTERVAL- Gap between probes.ELECTRIC_DATABASE_TCP_KEEPALIVE_COUNT- Unanswered probes before drop.ELECTRIC_DATABASE_TCP_USER_TIMEOUT- Max time data may stay unacknowledged.All unset by default, so behaviour is unchanged unless configured. Durations accept the usual 30s / 500ms forms.
Sample config:
Implementation:
ConnectionResolver.populate_tcp_opts/1now appends the options to:socket_options.SO_KEEPALIVEgoes through :inet's portable{:keepalive, true}; the rest use :raw with the LinuxIPPROTO_TCPoption numbers, guarded on:os.type()so non-Linux developer machines skip them rather than failing witheinval.Note: I've generated the PR with AI, because I don't know Elixir, but the change looks fairly straightforward to me, so I'm hoping it's all correct. The one thing that feels a bit risky is what happens on non-Linux kernels. The code attempts to disable this automatically in that case.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.