Skip to content

fix: propagate download errors through StartDockerImageDownload join function - #48487

Merged
pelikhan merged 3 commits into
mainfrom
copilot/code-quality-fix-goroutine-leak
Jul 28, 2026
Merged

fix: propagate download errors through StartDockerImageDownload join function#48487
pelikhan merged 3 commits into
mainfrom
copilot/code-quality-fix-goroutine-leak

Conversation

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

StartDockerImageDownload returned a func() join that blocked but discarded all errors, giving callers no way to detect pull failures. The defer ordering inside the goroutine also ran recover() after map cleanup, so a panic during cleanup would escape unrecovered.

Changes

pkg/cli/docker_images.go

  • Introduced inflightDownload struct (done chan struct{} + err error) replacing the raw chan struct{} in the inflight map
  • Changed return type from (bool, func())(bool, func() error); the join function now returns any download error after the goroutine exits
  • Fixed goroutine defer ordering (LIFO): recover+set-error → map cleanup → close(done), ensuring dl.err is always written before callers unblock
// Before
func StartDockerImageDownload(ctx context.Context, image string) (bool, func())

// After
func StartDockerImageDownload(ctx context.Context, image string) (bool, func() error)

// Join now surfaces failure:
started, join := StartDockerImageDownload(ctx, image)
if err := join(); err != nil {
    // handle pull failure
}

pkg/cli/docker_images_test.go

  • Updated TestStartDockerImageDownload_ConcurrentCalls and TestStartDockerImageDownload_RaceWithExternalDownload to collect all join functions and cancel the context at cleanup, eliminating goroutine leaks detected by goleak

pkg/cli/docker_images_test_helpers_test.go

  • ResetDockerPullState updated to initialize map[string]*inflightDownload

pkg/cli/README.md

  • Corrected StartDockerImageDownload and CheckAndPrepareDockerImages signatures in the public API table

- Add inflightDownload struct with done channel and err field
- Change StartDockerImageDownload return type to (bool, func() error)
- Fix defer ordering in goroutine: recover+set-error first, cleanup
  second, close-done last (callers only unblock after dl.err is set)
- Propagate download errors through dl.err field set before done closes
- Update concurrent tests to collect and join goroutines to prevent leaks
- Update README.md with correct function signature
- Fix pre-existing smoke-copilot-auto.lock.yml drift

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix goroutine leak in StartDockerImagePull fix: propagate download errors through StartDockerImageDownload join function Jul 28, 2026
Copilot AI requested a review from pelikhan July 28, 2026 02:42
@pelikhan
pelikhan marked this pull request as ready for review July 28, 2026 02:45
Copilot AI review requested due to automatic review settings July 28, 2026 02:45

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

Adds error propagation to Docker image download join functions and improves test cleanup.

Changes:

  • Stores completion errors alongside in-flight downloads.
  • Updates concurrent tests to cancel and join downloads.
  • Corrects public API documentation.
Show a summary per file
File Description
pkg/cli/docker_images.go Adds error-returning joins and panic handling
pkg/cli/docker_images_test.go Joins concurrent test downloads
pkg/cli/docker_images_test_helpers_test.go Updates in-flight state initialization
pkg/cli/README.md Corrects Docker API signatures
.github/workflows/smoke-copilot-auto.lock.yml Removes generated model-cost metadata

Review details

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Medium

Comment thread pkg/cli/docker_images.go
Comment on lines +176 to +177
// Defer order (LIFO): recover+set-error runs first, cleanup runs second,
// close(done) runs last so callers only unblock after dl.err is set.
Comment thread pkg/cli/docker_images.go
lastErr = fmt.Errorf("panic in docker image download for %s: %v", image, r)
dockerImagesLog.Printf("Panic in docker image download for %s (recovered): %v", image, r)
}
dl.err = lastErr
Comment thread pkg/cli/docker_images.go
Comment on lines +248 to +250
return true, func() error {
<-dl.done
return dl.err
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts on this branch.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan merged commit c830793 into main Jul 28, 2026
28 checks passed
@pelikhan
pelikhan deleted the copilot/code-quality-fix-goroutine-leak branch July 28, 2026 03:07
Copilot stopped work on behalf of pelikhan due to an error July 28, 2026 03:08
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.5

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.

[Code Quality] fix: add join point to StartDockerImagePull goroutine to prevent goroutine leak and use-after-free

3 participants