[BUG] swag-ondemand.py infinite loop on Docker daemon restart causes massive log spam and disk exhaustion

Open Beginner friendly
#1,158 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
docker, python

Research direction

Start in swag-ondemand.py at ContainerThread.run(self), especially the exception handler described in the issue. Review how Docker connection failures are logged, then verify during temporary Docker daemon unavailability that retries no longer flood ondemand.log or exhaust disk space.

Written by the indexing model from the issue text.

Description

no-issue-activity
Is there an existing issue for this?
  • I have searched the existing issues
Name of mod

swag-ondemand

Name of base container

swag

Current Behavior

When the Docker daemon is upgraded (e.g., via unattended-upgrades), the service restart takes long enough for the /var/run/docker.sock to be removed and recreated. During this window, swag-ondemand.py enters an unthrottled infinite loop, flooding ondemand.log with 502 Bad Gateway / 503 Service Unavailable errors (hundreds per second). This quickly consumes all host disk space, leading to OSError: [Errno 28] No space left on device and triggering a cascading failure of all other containers on the host.

I've verified the code: the issue is located in the run(self) method of ContainerThread class, where the except block executes a logging.exception(e) without any time.sleep(), causing a tight loop that creates hundreds of log entries per second upon connection failure.

Expected Behavior

The script should handle the temporary Docker daemon unavailability gracefully. It should implement a backoff or a delay in the except block of the main loop to prevent log flooding and resource exhaustion during daemon maintenance.

Steps To Reproduce

The issue is specifically reproducible during an automated Docker package upgrade. It is difficult to reproduce with a simple systemctl restart docker as the socket is often replaced fast enough to avoid triggering the sustained 502/503 loop.

  1. Ensure swag-ondemand is running.
  2. Trigger an apt upgrade docker-ce (which performs a full package replacement/restart).
  3. Observe ondemand.log growing at high speed due to the lack of a delay in the exception handler.
Environment
- OS: Ubuntu 24.04.3
- How docker service was installed: Docker's apt repository
CPU architecture

x86-64

Docker creation
services:
  nginx:
    image: lscr.io/linuxserver/nginx:latest
    container_name: redacted
    networks:
      - swag
    environment:
      PUID: ${PUID}
      PGID: ${PGID}
      TZ: ${TIMEZONE}
    volumes:
      - ./config:/config
      - /media/library/archive/redacted:/config/www
    restart: unless-stopped
    labels:
      - swag=enable
      - swag_url=sub.${DOMAIN_NAME}
      - swag_port=80
      - swag_auth=authelia
      - swag_ondemand=enable
      - swag_server_custom_directive=include /config/nginx/ondemand.conf;
      - swag_ondemand_urls=https://sub.
networks:
  swag:
    external: true
Container logs
.
Dominant language
No language data
Stars
1.5k
Forks
329
Avg merge
5h 5m
Merged PRs (30d)
1

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.

More from linuxserver/docker-mods

All issues in linuxserver/docker-mods

Similar issues

More DevOps issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.