Repository navigation
fix: do not stop accepting connections on transient errors - #577
Open
AndreyOsipuk wants to merge 2 commits into
Open
AndreyOsipuk wants to merge 2 commits into
AndreyOsipuk wants to merge 2 commits into
Conversation
Proxy.Serve returned on any Accept error and run_proxy started it with 'go proxy.Serve(listener)' ignoring the result, so running out of file descriptors under a connection flood (EMFILE) left the process alive but no longer accepting connections. utils.Listener also returned an error when socket options could not be set on one accepted connection (e.g. reset by the client right away), which stopped the accept loop because of one bad client. Temporary accept errors are now retried with a pause growing from 5ms to 1s, like net/http; a connection with broken socket options is closed and skipped; and if Serve still returns, runProxy shuts down and returns the error so a supervisor restarts the process.
The listener is closed during shutdown, so Serve returns an accept error and every stop or restart exited with code 1. Only a Serve that failed before shutdown started is reported now.
Author
|
Found on our production nodes after deploying this change: an ordinary |
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.
mtg can stay alive but stop accepting connections until it is restarted:
Proxy.Servereturns on anyAccepterror, andrunProxystarts it asgo proxy.Serve(listener) //nolint: errcheck. When a connection flood exhausts file descriptors (EMFILE), the accept loop ends while the process keeps running; process-level monitoring does not notice.utils.Listener.Acceptreturns an error when socket options cannot be set on one accepted connection (for example, a client that resets right after the TCP handshake), which ends the accept loop because of a single bad client.Changes:
EMFILE,ENFILE,ENOBUFS,ENOMEM,ECONNABORTED,ECONNRESET, timeouts) are retried with a pause growing from 5ms to 1s, asnet/httpdoes, with a warning in the log; shutdown interrupts the pause;Servestill returns an error,runProxyshuts down and returns it, so systemd/docker restarts the process.Tests:
acceptWithRetrysurvivesEMFILE, stops on a closed listener and on shutdown during the pause;IsTemporaryAcceptErrorand the delay cap;utils.Listenerskips a connection with a broken socket (fails on current master).go vet, tests andGOOS=windows/darwin go build ./...pass.The same fix for mtg-multi (which also covers its
MultiListener): dolonet#46.