Repository navigation
Conversation
When HEALTH_PORT is already taken, for example by another k8s-sidecar container in the same pod using the default 8080, the dual-stack bind fails with EADDRINUSE. The health server treated every OSError as "IPv6 not available", logged that warning, retried on IPv4, failed the same way and the health thread died with a traceback. Only fall back to IPv4 when the error is not EADDRINUSE, include the error in the fallback warning, and log one error naming the port and HEALTH_PORT when the server cannot start. Signed-off-by: YoungjuKim <[email protected]>
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.
When
HEALTH_PORTis already taken,_create_health_http_server()reports it as missing IPv6. That happens, for example, with two k8s-sidecar containers in one pod (Grafana's dashboards and datasources sidecars) that both use the default 8080. The dual-stack bind fails withEADDRINUSE, theexcept OSErrorbranch logsIPv6 not available, falling back to IPv4 for the health server, and the IPv4 bind then fails in the same way. The health thread then dies with an uncaught traceback (OSError: [Errno 98] Address in use), while the sidecar keeps running without a health endpoint.We saw this in the datasources sidecar of a Grafana pod (k8s-sidecar 2.10.1, Grafana chart 12.11.0, neither sidecar had
HEALTH_PORTset). The pod does have IPv6, so the warning sent us looking in the wrong place. Newer Grafana charts give each sidecar its ownHEALTH_PORT, but any pod with two sidecars on the default port still hits this.This PR:
EADDRINUSEfrom the IPv6 attempt instead of falling back, because the port is busy and IPv4 would fail the same way;IPv6 not available ([Errno 97] Address family not supported by protocol), ...;start_health_server(), catches theOSErrorand logs a single error instead of a traceback:Cannot start the health server on port 8080: [Errno 98] Address in use. Set HEALTH_PORT to a free port; each k8s-sidecar container in the same pod needs its own.Behaviour is otherwise unchanged: the sidecar keeps running without a health endpoint, as before. If you would rather have it exit in this case (so the conflict shows up as a failing container instead of a log line), I can change that.
Tests: added
test/unit/test_health_server.py(standard library only, liketest_liveness.py). I ranpython -m unittest discover -s test/unit -t test/unitinside thekiwigrid/k8s-sidecar:2.10.1image (Python 3.15.0b2) with this branch'ssrc/. All 16 tests pass. Withmain'ssrc/, the new port-in-use test fails on theIPv6 not availablewarning. I also startedstart_health_server()with a busyHEALTH_PORT. Onmainit prints the misleading warning and two tracebacks; with this change it prints the one error line above.This change was drafted with AI assistance and reviewed by me.
🤖 Generated with Claude Code