PrometheusSimple: per-host connection slot leaks when TimeoutThread lands in the close handler
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- haskell, prometheus
- Domain
- observability
Research direction
Start with hermod-tracing-prometheus/src/Hermod/Tracing/Prometheus/NetworkRun.hs, especially the forkFinally close handler and the connection-limiter paths at L143–L164; then read how withHandleKillThread and gracefulClose handle timeout exceptions. The issue reports no deterministic reproduction or named test, so first establish a reproducible case. Done means a late timeout cannot leak a per-host or global connection slot and subsequent scrapes are not refused.
Written by the indexing model from the issue text.
Description
cardano-node 11.2.0.164 (git rev b004fe0c), trace-dispatcher 2.13.1, network 3.2.9.0, time-manager 0.3.2; Leios prototype testnet, block producer.
Observed
After brief whole-process pauses (major GC under memory pressure), the node's stderr shows:
cardano-node: Thread killed by timeout manager
The BP logged this line five times in one day. After the fifth, every scrape from our Prometheus host is refused at once (read: connection reset by peer, ~2 ms). The same endpoint answers 200 to any other host. Inside the container's network namespace, ss -tn '( sport = :12798 )' shows only the listener and no open connections. The refusal persists (35+ minutes so far) while the node keeps running normally. A same-version node on another host with no pauses logged zero such lines and had zero failed scrapes.
Code path (trace-dispatcher-2.13.1, Cardano/Logging/Prometheus/NetworkRun.hs; unchanged on hermod-tracing master in hermod-tracing-prometheus/src/Hermod/Tracing/Prometheus/NetworkRun.hs)
- L90:
forkFinally (runServer mgr conn) (const $ gclose conn >> releasePeer peer).releasePeerruns only ifgclosereturns normally. - L96:
runServerusesT.withHandleKillThread. In time-manager 0.3.2, the kill fires asforkIO $ E.throwTo tid' TimeoutThread(registerKillThread).canceldoes not recall a throw already forked. - The
ignore TimeoutThreadhandler covers only the body ofwithHandleKillThread. A late throw is delivered in theforkFinallyhandler, which runs undermask(interruptible).gracefulCloseblocks inatomically(network 3.2.9.0,recvEOFevent), which is an interruptible point. The exception then abortsgclose, skipsreleasePeer, and escapes the thread. That escape is the stderr line above. - L159/L164: with
runConnLimitPerHost = 5, the fifth leaked slot for a peer address meanscanServeThisPeerreturnsFalse. L91 then callsclose connon every later connection from that address, which the client sees as RST/EOF.
A process-wide pause makes the race likely: the inactivity timer and the client's close are both pending when the RTS resumes.
Impact
Metrics from one monitoring host are lost until the node restarts, while the node itself is healthy. With connCountPerHost = 0 and a non-zero global limit, the same leak would count against runConnLimitGlobal (L153), so every host would be refused instead.
Workaround (from code; not tested on a live node)
Set "TracePrometheusSimpleRun": {"connCountGlobal": 0, "connCountPerHost": 0}. mkConnLimiter 0 0 (L143) disables the limiter. cardano-node passes this to runPrometheusSimpleWith (cardano-node/src/Cardano/Node/Tracing/API.hs:175-177 at b004fe0c). Alternatively, restart the node.
Not verified
- The exact interleaving. It is inferred from the code and from the one-to-one match between the stderr lines and the leaked slots. There is no deterministic reproduction yet.
- The workaround on a running node.
Related: IntersectMBO/cardano-node#6389 (same symptom; closed after #6396 added withHandleKillThread).
- Dominant language
- Haskell
- Stars
- 0
- Forks
- 2
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-ledger#6276 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenZeppelin/canton-contracts#92 ·
Maintainers usually reply within 1 day