Skip to content

fix(calibration): reap timed-out image fetch workers - #3855

Merged
Qubitium merged 2 commits into
mainfrom
fix/image-fetch-worker-cleanup
Nov 13, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/image-fetch-worker-cleanup

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3854.

A server that trickles response headers kept a daemon request thread and socket alive after total_timeout. Each network attempt now runs in a fresh subprocess; timeout or caller interruption kills and reaps it before returning. Successful and failed attempts also close their IPC pipes. The change is 271 insertions and 174 deletions across four files, including tests and the updated reference page.

The caller retains retries, backoff, image decoding and pixel limits. The worker retains requests' status/error handling and streaming byte limit. No private socket inspection or background fetch/watchdog thread remains.

flowchart TD
    A["load_image_from_url: absolute deadline"] --> B["_download_image_bytes: launch fresh interpreter"]
    B --> C["_image_fetch_worker: requests.get and bounded body read"]
    B --> D["communicate: remaining deadline"]
    C --> D
    D -- timeout or caller interruption --> E["kill child; drain pipes; reap"]
    E --> F["ImageFetchError or caller interruption"]
    D -- bytes --> G["Check pixel limit; decode; recheck deadline"]
    D -- retryable failure --> H["Backoff within shared deadline"]
    H --> B
    D -- permanent failure --> F
    classDef fail fill:#f8d7da,stroke:#b02a37,color:#000;
    class E,F fail;
Loading
Mechanism Before at d831ba08 After
Header read gptqmodel/utils/image.py:160–213: daemon thread stops being awaited but cannot interrupt requests.get Parent owns a killable subprocess covering DNS, TLS, headers, redirects and body
Cancellation/publication race image.py:185–208: response availability races cancellation Only bytes or JSON failure cross IPC; child exit releases sockets
Body deadline image.py:284–293: watchdog accesses private response sockets Same parent deadline terminates the complete network attempt

Committed flow and lifecycle contract, linked from README.

Validation:

  • python -m pytest tests/test_image_fetch.py -q -o log_cli=false --disable-warnings --maxfail=1: 28 passed on Python 3.14t with the GIL disabled.
  • New real-HTTP regression repeats three never-ending header responses and checks peer disconnect, no abandoned fetch threads, reaped children and closed pipes. It fails on the previous main because the socket stays open.
  • New caller-interruption regression checks cleanup while the server is still sending headers.
  • Existing normal fetch, transient retry, permanent failure, byte/pixel bounds, redirects, header/body timeouts and model-adapter tests pass.
  • bash format/check.sh (complete repository Ruff gate), git diff --check, and Mermaid fence validation pass.

Tradeoff: each network attempt pays fresh-interpreter startup, which counts against total_timeout. The worker executes the installed file with runpy.run_path, preserving user-site and PYTHONPATH dependency discovery without importing the GPT-QModel model registry or initializing accelerator state. Process teardown adds a small scheduling/reaping interval. Pillow decoding remains in the caller with deadline checks before/after; this change does not make the decoder interruptible.

@Qubitium
Qubitium merged commit e558938 into main Nov 13, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/image-fetch-worker-cleanup branch November 13, 2026 14:12
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.

[BUG] Image-fetch timeout leaves header-reading workers and sockets alive

1 participant