fix: zombie process on metrics server fail#1926
Conversation
✅ Deploy Preview for polite-licorice-3db33c canceled.
|
e419435 to
7d5aff6
Compare
fd96e57 to
181d80b
Compare
| s.serverMtx.RLock() | ||
| defer s.serverMtx.RUnlock() |
There was a problem hiding this comment.
The mutex+nil-check in the old shutdown goroutines was needed because those goroutines ran concurrently with server setup; the server field might not have been assigned yet when ctx.Done() fired. In the new code, serveWithShutdown is only called after the server is already assigned and receives it as a direct argument, so the race doesn't exist.
| } | ||
|
|
||
| func (s *ConnectService) startServer(svcConf service.Configuration) error { | ||
| func serveWithShutdown(ctx context.Context, server *http.Server, serveFn func() error) error { |
There was a problem hiding this comment.
I extracted this because we use it in a couple places to handle server shutdowns.
|
/gemini review |
181d80b to
a37ab39
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the server lifecycle management in ConnectService by introducing a serveWithShutdown helper function, which simplifies the Serve method and centralizes graceful shutdown logic. Feedback was provided regarding a potential race condition in serveWithShutdown where a server error could be masked if the context is cancelled at the same time, suggesting a check for errors after the shutdown process completes.
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
a37ab39 to
dd9033a
Compare
|
🤖 I have created a release *beep* *boop* --- <details><summary>flagd: 0.15.1</summary> ## [0.15.1](flagd/v0.15.0...flagd/v0.15.1) (2026-04-07) ### 🐛 Bug Fixes * object flags without `defaultVaraint` dont default in RPC ([#1925](#1925)) ([17f833e](17f833e)) * **security:** update module github.com/go-jose/go-jose/v4 to v4.1.4 [security] ([#1929](#1929)) ([cf22a11](cf22a11)) * zombie process on metrics server fail ([#1926](#1926)) ([0271068](0271068)) * mem leak due to unbounded metrics cardinality ([#1931](#1931)) ([176866e](176866e)) </details> <details><summary>flagd-proxy: 0.9.3</summary> ## [0.9.3](flagd-proxy/v0.9.2...flagd-proxy/v0.9.3) (2026-04-07) ### 🐛 Bug Fixes * **security:** update module github.com/go-jose/go-jose/v4 to v4.1.4 [security] ([#1929](#1929)) ([cf22a11](cf22a11)) </details> <details><summary>core: 0.15.1</summary> ## [0.15.1](core/v0.15.0...core/v0.15.1) (2026-04-07) ### 🐛 Bug Fixes * mem leak due to unbounded metrics cardinality ([#1931](#1931)) ([176866e](176866e)) * **security:** update module github.com/go-jose/go-jose/v4 to v4.1.4 [security] ([#1929](#1929)) ([cf22a11](cf22a11)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>



Fixes an issue where a failure of the metrics server to start can cause a zombie process.
This is hard and relatively low value to test with unit tests, but I was able to easily reproduce it with this simple script:
After the simple context handling, the script confirms the bug is fixed.
Fixes: #1807