DockerStatsService: docker stats child silently killed at execa maxBuffer (~100 min), stats freeze until resubscribe

Offen
#2,146 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
docker, node.js, typescript
Bereich
api, backend

Rechercherichtung

Start with api/src/unraid-api/graph/resolvers/docker/docker-stats.service.ts, focusing on how the service launches and handles the docker stats child process. Check how stream output is consumed and how exit events interact with active subscribers. The issue is done when stats continue updating while subscribed and an unexpected child exit is detected and handled.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Environment

Unraid OS Version: 7.4.0, API 4.37.11+8e587fe2

Are you using a reverse proxy?
No, not for this issue. The stats consumer (Home Assistant Unraid integration) connects to the server's LAN IP directly, and everything below was diagnosed from the server shell.

Pre-submission Checklist

  • I have verified that my Unraid OS is up to date
  • I have tested this issue by accessing my server directly (not through a reverse proxy)
  • This is not an Unraid Connect related issue (if it is, please submit via the support form instead)

Issue Description

DockerStatsService launches a long-lived docker stats child through execa (9.6.0) with the default buffer: true. The API reads stdout line by line through readline, but execa also buffers the full output, and terminates the subprocess once that buffer hits the default maxBuffer of 100 MB.

With 65 running containers, docker stats --format ... --no-trunc produces about 16.4 KB/s, so the child is killed about 100 minutes after every stream start.

The kill is never noticed:

  • The exit handler only acts on result.failed && !result.signal. Because the subprocess was terminated by a signal, nothing gets logged and stopStatsStream() is never called.
  • statsProcess therefore stays non-null, so startStatsStream() returns early (if (this.statsProcess) return;), and the stream is never respawned.

Every container-stats subscription then freezes on its last values until all subscribers disconnect (which triggers stopStatsStream()), or until unraid-api restart.

Code: api/src/unraid-api/graph/resolvers/docker/docker-stats.service.ts (still present on main at 8e587fe).

Steps to Reproduce

  1. Run a server with a reasonable number of containers (65 here) and subscribe to Docker container stats (the HA Unraid integration, or a GraphQL subscription in the sandbox).
  2. Watch the child: p=$(pgrep -f "CPUPerc.*no-trunc"); ps -o etime= -p $p; grep wchar /proc/$p/io
  3. When wchar reaches about 100,000,000 (~100 min here), the child disappears: pgrep -f "CPUPerc.*no-trunc" returns nothing. graphql-api.log has no entry for it, and the last DockerStatsService line is still Starting docker stats stream.

Rate check: timeout 60 docker stats --format '{{.ID}};{{.CPUPerc}};{{.MemUsage}};{{.MemPerc}};{{.NetIO}};{{.BlockIO}}' --no-trunc | wc -c → 985,200 bytes/60 s ≈ 16.4 KB/s → 100 MB in ~101 min.

Expected Behavior

The stats stream keeps running for as long as there are subscribers. If the child exits for any reason, the service notices and respawns it.

Actual Behavior

The stats stream stops silently about every 70-100 minutes, with nothing in the logs. Observed stream lifetimes from graphql-api.log Starting/Stopping pairs, compared with HA sensor history: about 85, 70, 95 and 100 minutes. Docker sensors freeze until something resubscribes.

Additional Context

Suggested fix:

this.statsProcess = execa('docker', ['stats', '--format', this.STATS_FORMAT, '--no-trunc'], {
    buffer: false,   // long-lived stream: never buffer (avoids maxBuffer termination)
    reject: false,
});
  • Drop all: true. Nothing reads .all, and an unconsumed merged stream with buffering off can backpressure stdout.
  • Treat any child exit (including signal and isMaxBuffer) as end-of-stream: clear statsProcess, log it, and respawn while subscribers remain.

Locally, patching the built plugin.module-*.js from all: true to buffer: false resolves it.

Ruled out along the way: the Docker daemon (docker stats --no-stream stays responsive throughout), container OOMs, and container create/destroy/restart events (none of them kill the child).

Vorherrschende Sprache
TypeScript
Sterne
123
Forks
25
Ø Merge
2 T. 16 Std.
Gemergte PRs (30 T.)
9

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus unraid/api

Alle Issues in unraid/api

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.