Repository navigation
remotes: close fetch reader immediately on EOF - #13438
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent CRI image pulls from being prematurely canceled by the progress timeout when the network download has finished but content.Copy is still committing to the content store (e.g., due to slow/blocked DB commits). It does this by closing the remote fetch HTTP reader immediately upon hitting io.EOF, so the progress reporter no longer sees an “active” HTTP request during the commit phase.
Changes:
- Wrap the fetcher-provided
io.ReadCloserwith acloseOnEOFReaderinFetchand defer closing the wrapper. - Add a
closeOnEOFReadertype that closes the underlying reader as soon asReadreturnsio.EOF, withsync.Onceto avoid double-closing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
953eebf to
e3dbfd5
Compare
e3dbfd5 to
86865d5
Compare
|
Per offline comment from @dmcgowan, embedded closeOnEOFReader into closeOnEOFReadSeeker. |
The CRI progress reporter cancels an image pull if it sees no progress for 5 seconds. It tracks this through active HTTP requests. During remote fetches, the HTTP response reader is closed via a deferred call after `content.Copy` completes. Diagnosis: `content.Copy` handles both downloading the stream and committing the writer to the content store. Any delays during the database commit phase (e.g. from database locks, slow disk syncs, or concurrent pull deduplication blocks) keep the HTTP connection open. The progress reporter sees the request is still active (`activeReqs = 1`) but no new bytes are coming in, leading to a premature timeout cancellation. Reproduction: We reproduced this flakiness deterministically on a GCE VM under a simulated 2 Mbps ingress bandwidth limit using Linux traffic control ingress policing (`tc filter ... action police rate 2mbit`). Under this slowness, the download took longer than the progress timeout during the slow commit phase, triggering context cancellation and failing the `TestCRIImagePullTimeout/HoldingContentOpenWriterWithLocalPull` test. Solution: To fix this, we wrap the HTTP reader in a `closeOnEOFReader` or `closeOnEOFReadSeeker` before handing it to `content.Copy`. If the underlying connection reader implements `io.Seeker`, it is dynamically wrapped in `closeOnEOFReadSeeker` to forward `Seek` operations. This ensures that O(1) Range seeks are fully preserved during network resumes or retries. The wrappers automatically close the underlying network stream as soon as `Read()` returns `io.EOF` (when the download completes, before the database commit begins). This drops `activeReqs` to `0` early, freeing the socket and preventing progress timeouts during commits. A `sync.Once` ensures that subsequent deferred `Close()` calls do not double-decrement the reporter. How it was tested: Verified the fix on a GCE VM under a simulated 2 Mbps ingress bandwidth limit. Verified seeker safety via standalone logic audits and trace proofs. Assisted-by: Antigravity Signed-off-by: Samuel Karp <[email protected]>
The TestCRIImagePullTimeout test case "NoDataTransferred" flaked under constrained networks because the test proxy mirror registry used a blocking ReadAtLeast call to forward bytes to containerd. This blocking wait (up to 4KB) meant the mirror registry server completely stopped forwarding data during network slowness, triggering containerd's aggressive 5-second progress timeout and canceling the pull before it could reach its 3MB circuit-breaker limit. This is resolved by changing the proxy's custom copy loop from io.ReadAtLeast(src, buf, len(buf)) to standard src.Read(buf). This streams network chunks to containerd immediately as they arrive, preventing false timeout cancellations while maintaining correct circuit-breaker byte tracking. Assisted-by: Antigravity Signed-off-by: Samuel Karp <[email protected]>
86865d5 to
45cc0c5
Compare
|
I think we don't need to add this wrapper based on my existing patch - https://github.com/containerd/containerd/pull/9369/changes I can confirm the The question is that the transfer service is using different logic which depends on status. containerd/internal/cri/server/images/image_pull.go Lines 956 to 967 in 9eed061 Based on #9369, it will close reader on EOF so we don't need this change actually. So could we just revert this and apply that change 6c396d0 into this line as well? |
The CRI progress reporter cancels an image pull if it sees no progress
for 5 seconds. It tracks this through active HTTP requests. During
remote fetches, the HTTP response reader is closed via a deferred
call after
content.Copycompletes.Diagnosis:
content.Copyhandles both downloading the stream and committingthe writer to the content store. Any delays during the database
commit phase (e.g. from database locks, slow disk syncs, or concurrent
pull deduplication blocks) keep the HTTP connection open. The progress
reporter sees the request is still active (
activeReqs = 1) but no newbytes are coming in, leading to a premature timeout cancellation.
Reproduction:
We reproduced this flakiness deterministically on a GCE VM under a
simulated 2 Mbps ingress bandwidth limit using Linux traffic control
ingress policing (
tc filter ... action police rate 2mbit). Under thisslowness, the download took longer than the progress timeout during the
slow commit phase, triggering context cancellation and failing the
TestCRIImagePullTimeout/HoldingContentOpenWriterWithLocalPulltest.Solution:
To fix this, we wrap the HTTP reader in a
closeOnEOFReaderorcloseOnEOFReadSeekerbefore handing it tocontent.Copy. If theunderlying connection reader implements
io.Seeker, it is dynamicallywrapped in
closeOnEOFReadSeekerto forwardSeekoperations. Thisensures that O(1) Range seeks are fully preserved during network
resumes or retries. The wrappers automatically close the underlying
network stream as soon as
Read()returnsio.EOF(when the downloadcompletes, before the database commit begins). This drops
activeReqsto
0early, freeing the socket and preventing progress timeoutsduring commits. A
sync.Onceensures that subsequent deferredClose()calls do not double-decrement the reporter.How it was tested:
Verified the fix on a GCE VM under a simulated 2 Mbps ingress
bandwidth limit. Verified seeker safety via standalone logic audits
and trace proofs.
Assisted-by: Antigravity