Skip to content

fix(metric): avoid metrics mux conflict across instances#628

Open
Ecattea wants to merge 1 commit intoanyproto:mainfrom
Ecattea:fix/metrics-mux-conflict
Open

fix(metric): avoid metrics mux conflict across instances#628
Ecattea wants to merge 1 commit intoanyproto:mainfrom
Ecattea:fix/metrics-mux-conflict

Conversation

@Ecattea
Copy link
Copy Markdown

@Ecattea Ecattea commented Feb 25, 2026

Use per-instance ServeMux in Run and add regression test for multi-instance panic.


  • I understand that contributing to this repository will require me to agree with the CLA

Description

This PR fixes a panic when multiple metric instances are created in the same process.

Root cause:

  • metric.Run used global http.DefaultServeMux via http.Handle("/metrics", ...) and http.ListenAndServe(addr, nil).
  • Re-registering /metrics across instances could panic with pattern conflict.

Changes:

  • Use per-instance mux in metric.Run:
    • mux := http.NewServeMux()
    • mux.Handle("/metrics", ...)
    • http.ListenAndServe(addr, mux)
  • Make startup error channel buffered to avoid potential goroutine blocking after timeout.
  • Add regression test TestRun_DoesNotPanicWithMultipleInstances.

Validation:

  • go test ./metric -run TestRun_DoesNotPanicWithMultipleInstances -count=50 -v
  • go test ./metric -count=1 -v

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings

N/A (backend-only change)

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added to documentation?

  • 📜 README.md
  • 📓 tech-docs
  • 🙅 no documentation needed

[optional] Are there any post-deployment tasks we need to perform?

None.

Use per-instance ServeMux in Run and add regression test for multi-instance panic.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Ecattea
Copy link
Copy Markdown
Author

Ecattea commented Feb 25, 2026

I have read the CLA Document and I hereby sign the CLA

@Ecattea
Copy link
Copy Markdown
Author

Ecattea commented Feb 26, 2026

The failing step check looks like a fork-permission issue, not a code/test issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic on registering /metrics globally

1 participant