0211 - A provider download runs on a worker the run stops waiting for
Date: 2026-11-29
Area: runtime, embedding
Related: ADR 0196, ADR 0207, ADR 0198, #2295, #1331
Context
A provider package's file was downloaded on the engine thread, inside the
module resolution that needed it (TGocciaHTTPProviderTransport.Get). Only
the request's own socket deadline could end it, which
#1331 had bounded by
the run's deadline. Two waits stayed outside every bound of the run. The
system resolver (getaddrinfo) cannot be interrupted, so a stalled DNS lookup
lasted as long as the resolver's own timeouts. An embedder's abort handle
(ADR 0198) sets the
thread's interrupt, which nothing on that path read: an abort requested 0.3 s
into a stalled download ended the run after the request's 60 s bound
(#2295).
fetch had solved the same problem for its requests: each runs on a worker
with a TNetworkCancellation, and the engine waits on the run's events, which
an abort wakes (ADR 0196).
A provider download differs in one respect: the resolution that waits for it
is synchronous, so the engine thread cannot go on with other work while it
waits, and once the run has ended it has nothing left to wait for.
Decision
A provider download runs on a worker thread of its own, and the thread that needs it waits for its answer, its deadline or its host's abort, whichever comes first. At the deadline or the abort it cancels the request and stops waiting, and the worker ends on its own.
- The request is a counted
TGocciaProviderRequest, held by the waiting thread and the worker, and freed by the last to let go. It owns everything the request uses: the URL, the pinned host and the check that holds every hop to it, the allowed-host list, the cancellation, the completion event and the answer. The worker touches nothing else, so a worker the run gave up on never reaches the transport, the package store or the engine, which may be gone by the time it ends. - The package cache is written by the waiting thread alone, with an answer it received and whose SHA-256 matches its pin. A download the run stopped waiting for writes nothing.
- The wait follows ADR 0207: the
transport, below the engine, waits through
WaitForNativeEventinGoccia.NativeLimits, and the engine installsNativeWaitHookfor the life of the thread's VM besideNativeWorkHook. The hook is the engine'sWaitForRunEvent, which a host's abort wakes, and it reports the abort. A wait cannot useNativeWorkHook, which charges work and leaves the engine's error pending. The deadline stays the one the transport is given (the run's plus 100 ms of slack, #1331). - A resolution that a deadline or an abort cut short ends the run as its
timeout or the abort does, past every handler, for a static import and an
import()alike. No download starts once the deadline has passed or the run was aborted. - Without a run (install mode) there is no hook: the request waits for its answer or its own 60 s bound, as before.
Consequences
- A run whose download is stalled anywhere, the DNS lookup included, ends at
its deadline or its abort.
scripts/engine/provider-deadline-test.pasmeasures both against a stalled loopback server and a lookup that ignores its cancellation: each run ends within a few milliseconds of 300 ms past its start, or 400 ms with the deadline's slack. - A worker abandoned during a stalled lookup keeps a thread and a socket until
the lookup returns, which the resolver's own timeouts bound. Unlike
fetch, nothing caps these threads, but each needs a run that ended while its download was stalled, and one run makes at most one download at a time. - Every application and embedder that imports provider packages needs thread
support, as
fetchalready does (cthreadson Unix). - The transport's test seam is
NewRequestandTGocciaProviderRequest.Send, which runs on the worker and may use only the request's own state.