unraid / unraid/api

Docker container cache not invalidated on external state changes

Open
#1,840 1 comment 0 reactions 1 assignee View on GitHub

@pujitm is already working on this.

Since Dec 15, 2025.

bug
Dominant language
TypeScript
Stars
113
Forks
22
Avg merge
10h 40m
Merged PRs (30d)
13

Description

Unraid OS Version:
7.2.2 (Latest)

Are you using a reverse proxy?
No - Issue tested with direct access to server.

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

The Docker service caches container state for 60 seconds (CACHE_TTL_SECONDS = 60 in docker.service.ts). While this cache is
correctly invalidated after GraphQL mutations (start/stop), it is NOT invalidated when containers are started/stopped from
external sources (Unraid WebUI, Docker CLI, etc.).

This causes third-party apps polling the GraphQL API to show stale container state for up to 60 seconds when users manage
containers from sources other than the API.

Steps to Reproduce

  1. Query Docker containers via GraphQL API (e.g., using docker { containers { ... } })
  2. Stop a running container using Unraid WebUI (not the GraphQL API)
  3. Query Docker containers again via GraphQL API within 60 seconds
  4. Observe that the API still returns the container as "running"

Expected Behavior

Container state should reflect actual Docker state within a reasonable time (5-10 seconds maximum).

Actual Behavior

Container state is cached for up to 60 seconds, returning stale data when containers are managed from sources other than the
GraphQL API (WebUI, CLI, etc.).

Additional Context

Technical Details:

File: api/src/unraid-api/graph/resolvers/docker/docker.service.ts

The cache is cleared after API mutations:

public async start(id: string): Promise<DockerContainer> {
  // ... start container logic
  await this.clearContainerCache();  // ✅ Cache cleared here
  return this.getContainer(id);
}

But there's no mechanism to invalidate cache when Docker events occur externally.

Suggested Solutions:

  1. Reduce cache TTL to 5-10 seconds for container state queries
  2. Listen to Docker events (docker events) and invalidate cache on container state changes
  3. Add GraphQL subscription for real-time container state updates (similar to array subscriptions)

Discovered while developing a third-party mobile app that polls the GraphQL API for Docker container status."

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.