Skip to content

remotes/docker: activity-based timeout for blob transfers - #13571

Open
beckend wants to merge 14 commits into
containerd:mainfrom
beckend:feature/activity-based-timeout
Open

beckend wants to merge 14 commits into
containerd:mainfrom
beckend:feature/activity-based-timeout

Conversation

@beckend

@beckend beckend commented Jun 10, 2026 •

Copy link
Copy Markdown

Problem

When pushing large images (10GB+) via nerdctl → containerd → distribution registry, uploads fail with timeout errors. The same ResponseHeaderTimeout can also cause pull failures when registries are slow to send response headers.

Root Cause

ResponseHeaderTimeout: 30s in registry.go:267 fires after the request body is sent but before the server responds with the final status. For large uploads that take longer than 30s to receive the final 201 response, the client aborts. For pulls, slow registries that take >30s to send response headers also fail.

Solution

Implement activity-based timeout detection for both push and pull paths:

  • New Clock/Ticker interfaces for mockable time in tests
  • New ActivityTracker to track I/O activity and detect stalls
  • activityPipeWriter calls Touch() on each write to track push activity
  • httpReadSeeker calls Touch() on each successful read to track pull activity
  • Activity-aware Commit() loop: 30s stall detection, respects ctx.Done()
  • Disable ResponseHeaderTimeout when ActivityTracker is present in context
  • Wire up tracker in both pusher.push() and fetcher.Fetch()/FetchByDigest()
  • Reuse existing tracker from context if caller already set one
  • sync.Cond-based pipe readiness to avoid goroutine deadlock in concurrent writes
  • Transport cloned via tr.Clone() with new httpFallback wrapper to avoid races

Testing

  • Unit tests for ActivityTracker with mock clocks (no real sleeps)
  • Push activity tests: write tracking, commit stall detection, context cancellation
  • Pull activity tests: fetch/fetchByDigest tracker creation, reuse, and read tracking
  • Integration tests with MockRegistryServer for slow registry scenarios
  • mockClock starts at non-zero time to avoid zero-value sentinel issues

Copilot AI review requested due to automatic review settings June 10, 2026 14:47
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jun 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Introduces activity tracking across Docker remote operations to better detect stalls/timeouts during long-running pushes/pulls, and to avoid transport mutation races by cloning request transports.

Changes:

  • Add ActivityTracker (with clock abstraction) and context helpers to propagate it through request paths.
  • Update request execution to (attempt to) clone transports and disable ResponseHeaderTimeout when activity tracking is enabled.
  • Add activity-aware push commit loop and read-seeker deadline/activity behavior, plus extensive new tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
core/remotes/docker/activity.go Adds activity tracker + clock abstractions used for stall detection.
core/remotes/docker/resolver.go Adds context plumbing and transport unwrapping/cloning in request.do.
core/remotes/docker/pusher.go Wires activity tracking into push path and adds activity-aware commit waiting logic.
core/remotes/docker/httpreadseeker.go Adds optional activity tracking + deadline handling during reads.
core/remotes/docker/activity_test.go Unit tests for activity tracker behavior/concurrency.
core/remotes/docker/resolver_activity_test.go Tests context round-trip + request transport timeout behavior.
core/remotes/docker/pusher_activity_test.go Tests push-writer activity touch behavior and commit behavior.
core/remotes/docker/httpreadseeker_activity_test.go Tests read-seeker touch behavior and concurrency.
core/remotes/docker/activity_timeout_integration_test.go Integration-style tests around slow registry behavior and activity tracking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/remotes/docker/activity.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/activity_test.go Resolved
beckend added a commit to beckend/containerd that referenced this pull request Jun 10, 2026
Address review feedback from PR containerd#13571:

- TimeSinceLastActivity: handle last == 0 (never touched)
- pusher.go: use pw.deadlineClock.Now() for consistent deadline init
- resolver.go: use tr.Clone() and create new httpFallback wrapper
- httpreadseeker.go: preserve partial reads on deadline expiration
- Add TestTimeSinceLastActivityNeverTouchedRealClock test
- Fix mock clock usage in integration tests
- Fix activity verifier and mock to use Clock interface
Copilot AI review requested due to automatic review settings June 10, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.

Comments suppressed due to low confidence (1)

core/remotes/docker/httpreadseeker.go:1

  • Two concrete concurrency problems in Read: (1) it holds hrs.mu while calling the potentially blocking rd.Read(p), which can block Close()/Seek() from acquiring the lock and may prevent shutdown/unblocking; (2) in the io.ErrUnexpectedEOF path it calls hrs.reader() while already holding hrs.mu, which will deadlock because reader() tries to lock the same mutex. Restructure to avoid holding the mutex across network I/O and call readerLocked() (or unlock before calling reader()) when the lock is already held.
/*

Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
Comment thread core/remotes/docker/activity.go Resolved
Copilot AI review requested due to automatic review settings June 10, 2026 23:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 13 comments.

Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
beckend added a commit to beckend/containerd that referenced this pull request Jun 10, 2026
Address review feedback from PR containerd#13571:

- TimeSinceLastActivity: handle last == 0 (never touched)
- pusher.go: use pw.deadlineClock.Now() for consistent deadline init
- resolver.go: use tr.Clone() and create new httpFallback wrapper
- httpreadseeker.go: preserve partial reads on deadline expiration
- Add TestTimeSinceLastActivityNeverTouchedRealClock test
- Fix mock clock usage in integration tests
- Fix activity verifier and mock to use Clock interface

Signed-off-by: Linken Quy Dinh <[email protected]>
@beckend
beckend force-pushed the feature/activity-based-timeout branch from fea425c to fcfd9a8 Compare June 10, 2026 23:29
beckend added a commit to beckend/containerd that referenced this pull request Jun 10, 2026
Address review feedback from PR containerd#13571:

- TimeSinceLastActivity: handle last == 0 (never touched)
- pusher.go: use pw.deadlineClock.Now() for consistent deadline init
- resolver.go: use tr.Clone() and create new httpFallback wrapper
- httpreadseeker.go: preserve partial reads on deadline expiration
- Add TestTimeSinceLastActivityNeverTouchedRealClock test
- Fix mock clock usage in integration tests
- Fix activity verifier and mock to use Clock interface

Signed-off-by: Linken Quy Dinh <[email protected]>
@beckend
beckend force-pushed the feature/activity-based-timeout branch from fcfd9a8 to 86f1b28 Compare June 10, 2026 23:40
Copilot AI review requested due to automatic review settings June 11, 2026 00:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Copilot AI review requested due to automatic review settings June 11, 2026 01:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
Copilot AI review requested due to automatic review settings June 11, 2026 02:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/httpreadseeker.go Resolved
Comment thread core/remotes/docker/activity.go Resolved
beckend added 10 commits June 11, 2026 05:13
This change implements activity-based timeout tracking for blob uploads
to prevent premature timeouts when pushing large images to registries.

Key changes:
- Add ActivityTracker interface with mockable Clock for testable time
- Store window in ActivityTracker struct for use in Stalled() checks
- Add activityPipeWriter to track I/O activity during writes
- Wire up ActivityTracker in push code path (was passing nil before)
- Add deadlineClock field to pushWriter for consistent time measurement
- Modify pushWriter.Commit() to use activity-aware timeout:
  - 5 minute total timeout with 5 second activity window
  - Uses ticker instead of time.After() to avoid timer leaks
  - Extends deadline when activity resumes after stall
  - Fixed early return bug when pipeC received with nil pipe
- Add deadline-based timeout to httpReadSeeker.Read() for read operations
- Modify request.do() to disable ResponseHeaderTimeout when
  ActivityTracker is present in context (preserving transport wrappers)
- Clone transport when modifying to avoid race conditions

Fixes:
- Window parameter now stored and used in ActivityTracker
- Fixed time.Now() vs mock clock mismatch in Commit loop
- Fixed nil pipe handling causing early return
- Fixed r.size > 0 condition that excluded GET requests
- Fixed transport wrapper preservation when cloning
- Fixed weak test assertions (GreaterOrEqual to 0 always true)
- Reduced 6-minute timeouts to 30 seconds
- Replaced time.Sleep with mock clock advancement in tests

All code paths are covered by unit tests using mock clock
to avoid timing-dependent flakiness.

Signed-off-by: Linken Quy Dinh <[email protected]>
Address review feedback from PR containerd#13571:

- TimeSinceLastActivity: handle last == 0 (never touched)
- pusher.go: use pw.deadlineClock.Now() for consistent deadline init
- resolver.go: use tr.Clone() and create new httpFallback wrapper
- httpreadseeker.go: preserve partial reads on deadline expiration
- Add TestTimeSinceLastActivityNeverTouchedRealClock test
- Fix mock clock usage in integration tests
- Fix activity verifier and mock to use Clock interface

Signed-off-by: Linken Quy Dinh <[email protected]>
- Fix gofmt formatting issues in activity.go, pusher.go, resolver.go, httpreadseeker.go
- Fix gofmt formatting in test files
- Remove unused newHTTPReadSeekerWithDeadline function

Signed-off-by: Linken Quy Dinh <[email protected]>
Fix remaining review issues and pre-existing bugs discovered:

Bug fixes:
- pusher.go: remove unused var err error declaration
- pusher.go: fix deadline logic - deadline now honors 5min total timeout
- pusher.go: add mutex to protect pw.pipe concurrent access (data race)
- httpreadseeker.go: fix mutex deadlock on io.ErrUnexpectedEOF path
- httpreadseeker.go: restructure to not hold mutex during blocking I/O
- activity.go: store window param in ActivityTracker struct
- activity_timeout_integration_test.go: fix touchCount data race (atomic ops)
- resolver.go: fix misleading nil transport warning message

Signed-off-by: Linken Quy Dinh <[email protected]>
Remove redundant pw.Close() after apw.Close() since apw.Close()
already closes the underlying pipe. The second close would return
io.ErrClosedPipe.

Signed-off-by: Linken Quy Dinh <[email protected]>
…ealActivityTracker

Use Stalled() check instead of TimeSinceLastActivity() != 0 to avoid
timing sensitivity on Windows CI where clock resolution can cause the
duration to be 0 immediately after Touch().

Signed-off-by: beckend <[email protected]>
Signed-off-by: Linken Quy Dinh <[email protected]>
- Fix deadlock in httpReadSeeker.Read(): replace defer hrs.mu.Unlock()
  inside loop with explicit unlocks before continue/return paths
- Remove premature Touch() in pushWriter.Write() before actual pipe
  write; rely on activityPipeWriter for activity tracking
- Narrow pipeMu lock scope: move GetStatus() outside pipeMu since it
  has its own internal mutex
- Add doc comments to exported WithActivityTracker and
  ActivityTrackerFromContext functions
- Downgrade nil transport log from Warn to Debug to reduce noise
- Fix TestActivityPipeWriterWriteCallsTouch to use mock and assert
  Touch() was actually called
- Rename TestActivityTrackerContextKeyDoesNotCollide to
  TestActivityTrackerFromContextReturnsFalseForWrongType
- Replace brittle server.URL[7:] with url.Parse() helper
- Remove misleading size gating comments from resolver tests

Signed-off-by: beckend <[email protected]>
Signed-off-by: Linken Quy Dinh <[email protected]>
The test sent only one pipe on pipeC but multiple concurrent writers
could see pw.pipe == nil and all block on pipeC. Only one writer would
receive the pipe; the rest would block forever, causing a 10m timeout.

Fix by pre-setting pw.pipe directly under pipeMu before starting
concurrent writers, so all writers immediately see pw.pipe != nil.

Signed-off-by: beckend <[email protected]>
Signed-off-by: Linken Quy Dinh <[email protected]>
- Remove unused loop variable in httpReadSeeker.Read()
- Handle replacePipe error return in pushWriter.Write() nil-pipe branch

Signed-off-by: beckend <[email protected]>
Signed-off-by: Linken Quy Dinh <[email protected]>
Replace the hardcoded 5-minute deadline with a 30s activity-based
stall check matching the original ResponseHeaderTimeout. If no data
has flowed through the stream for 30s, abort. Also respect callers

Signed-off-by: Linken Quy Dinh <[email protected]>
- Reuse existing ActivityTracker from context instead of overwriting
- Close pushWriter on stall timeout to prevent resource leaks
- Move mockClock/mockTicker/NewActivityTrackerWithClock to test-only
  file (clock_test_helpers_test.go)
- Add upper bound to TestCommitStallTimeoutWithMockClock tick loop

Signed-off-by: beckend <[email protected]>
Signed-off-by: Linken Quy Dinh <[email protected]>
@beckend
beckend force-pushed the feature/activity-based-timeout branch from a79ddac to 8ca3c30 Compare June 11, 2026 03:14
All test trackers using mockClock{now: 0} cause Stalled() to return
false when lastActivity is 0, since 0 is the zero-value sentinel.
Initialize with time.Now().UnixNano() to match production behavior.

Also replace pw.pipeC <- with pipeMu-protected pw.pipe assignment
in TestActivityTrackingWithMockTracker to match the fix applied to
TestPushBlobWithConcurrentActivity.

Signed-off-by: Linken Quy Dinh <[email protected]>
Copilot AI review requested due to automatic review settings June 11, 2026 05:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/resolver.go Resolved
beckend added 2 commits June 11, 2026 07:27
Wire up ActivityTracker in Fetch() and FetchByDigest() so the resolver
disables ResponseHeaderTimeout during active data transfer. This mirrors
the push path where the tracker prevents premature timeouts on slow
registries that take >30s to send response headers.

The tracker is passed to newHTTPReadSeeker so Touch() is called on
successful reads, keeping the activity timestamp fresh. Parallel chunk
downloads share the same tracker via inherited context.

Signed-off-by: Linken Quy Dinh <[email protected]>
Copilot AI review requested due to automatic review settings June 11, 2026 08:53
@beckend beckend changed the title remotes/docker: activity-based timeout for blob uploads remotes/docker: activity-based timeout for blob transfers Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/pusher.go Resolved
Comment thread core/remotes/docker/httpreadseeker.go Resolved
@kubernetes-prow

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants