Repository navigation
Conversation
There was a problem hiding this comment.
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
ResponseHeaderTimeoutwhen 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.
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
There was a problem hiding this comment.
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 holdshrs.muwhile calling the potentially blockingrd.Read(p), which can blockClose()/Seek()from acquiring the lock and may prevent shutdown/unblocking; (2) in theio.ErrUnexpectedEOFpath it callshrs.reader()while already holdinghrs.mu, which will deadlock becausereader()tries to lock the same mutex. Restructure to avoid holding the mutex across network I/O and callreaderLocked()(or unlock before callingreader()) when the lock is already held.
/*
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]>
fea425c to
fcfd9a8
Compare
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]>
fcfd9a8 to
86f1b28
Compare
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]>
a79ddac to
8ca3c30
Compare
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]>
Signed-off-by: Linken Quy Dinh <[email protected]>
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]>
|
PR needs rebase. DetailsInstructions 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. |
Problem
When pushing large images (10GB+) via nerdctl → containerd → distribution registry, uploads fail with timeout errors. The same
ResponseHeaderTimeoutcan also cause pull failures when registries are slow to send response headers.Root Cause
ResponseHeaderTimeout: 30sinregistry.go:267fires 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:
Clock/Tickerinterfaces for mockable time in testsActivityTrackerto track I/O activity and detect stallsactivityPipeWritercallsTouch()on each write to track push activityhttpReadSeekercallsTouch()on each successful read to track pull activityCommit()loop: 30s stall detection, respectsctx.Done()ResponseHeaderTimeoutwhenActivityTrackeris present in contextpusher.push()andfetcher.Fetch()/FetchByDigest()sync.Cond-based pipe readiness to avoid goroutine deadlock in concurrent writestr.Clone()with newhttpFallbackwrapper to avoid racesTesting
ActivityTrackerwith mock clocks (no real sleeps)MockRegistryServerfor slow registry scenariosmockClockstarts at non-zero time to avoid zero-value sentinel issues