BUG/MINOR: configure: pick the first valid UNIX socket from HAPROXY_MASTER_CLI - #416
Open
fabiomatavelli wants to merge 1 commit into
Open
Conversation
…ASTER_CLI Since HAProxy commit 8a02257d, HAPROXY_MASTER_CLI advertises the master CLI as a list of addresses separated by ";", for example "unix@/var/run/master.sock;sockpair@7". The whole value was handed over to the runtime client, which failed to dial a socket path that does not exist and made the Data Plane API exit. HAProxy reacts to that with exit-on-failure and kills every process, which is the failure reported in the issue. Split the value, keep only the UNIX addresses and use the first one that is already bound, falling back to the first valid candidate so that a delayed runtime start still picks it up. The UNIX socket check now rejects the empty string and every address family other than "unix@". Together with the caller no longer overriding the master runtime when no socket was found, a value set through --master-runtime or haproxy.master_runtime is not silently replaced by an empty string any more.
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.
Fixes #329. This picks up the work started in #330, which was closed by its author, and addresses the review feedback left there.
Problem
Since haproxy/haproxy@8a02257, HAProxy advertises its master CLI as a
;-separated list of addresses, soHAPROXY_MASTER_CLInow looks like:configureAPIonly stripped theunix@prefix and passed the rest through, so the runtime client tried to dial a socket literally named/data/haproxy/run/master-socket;sockpair@7:When the Data Plane API runs from a
programsection this makes it exit, and HAProxy tears down the whole process tree throughexit-on-failure.Changes
misc.MasterSocketFromEnv(value string) (string, bool)parses the raw environment value:;and keeps only the UNIX addresses, so any other address family HAProxy may add later is ignored instead of breaking the parsingos.Statplusos.ModeSocket)runtime_options.AllowDelayedStartexists precisely to wait for a socket HAProxy has not bound yet, so a hard existence check here would regress those setupsfalsewhen there is no usable UNIX socket at allmisc.IsUnixSocketAddrnow rejects the empty string, and accepts an<family>@prefix only when the family isunix. Previously"",sockpair@7andfd@3all returnedtrue.configureAPIonly overrideshaproxyOptions.MasterRuntimewhen a socket was actually found, and logs a warning otherwise. This is what keeps a master runtime set through--master-runtime/haproxy.master_runtimefrom being silently replaced by an empty string.Tests: table-driven unit tests for both functions in
misc/misc_test.go, binding real UNIX sockets so theos.ModeSocketbranch is genuinely exercised.Review comments from #330
HAPROXY_MASTER_CLIis;-separated and may hold several entries, split it and use the first validunix@oneMasterSocketFromEnvsplits and iterates, first bound socket winsIsUnixSocketAddr("")istrue, so an unset variable wipes a user-suppliedMasterRuntimeIsUnixSocketAddrrejects"", and the caller only assigns when a socket was foundIsUnixSocketAddrshould validate the address properly, including that the socket existsIsUnixSocketAddr, the existence check lives inMasterSocketFromEnvwhere a filesystem lookup is meaningful and where a delayed start can still be honouredNotes
abns@namenow returnsfalsefromIsUnixSocketAddr. The runtime client cannot dial abstract-namespace sockets anyway, so this turns a confusing dial failure into an explicit skip.go build ./...,go test ./...,make lint(0 issues) andmake check-commitall pass.