Skip to content

Commit 7f4e5d6

Browse files
committed
store: Wait for progress reporters updates to finish (docker#89)
This ensures the caller of the Write() method can use the same writer without risking a write race condition. Signed-off-by: Dorin Geman <dorin.geman@docker.com>
1 parent c228907 commit 7f4e5d6

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

pkg/distribution/internal/store/store.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ func (s *LocalStore) Version() string {
183183

184184
// Write writes a model to the store
185185
func (s *LocalStore) Write(mdl v1.Image, tags []string, w io.Writer) error {
186-
187186
// Write the config JSON file
188187
if err := s.writeConfigFile(mdl); err != nil {
189188
return fmt.Errorf("writing config file: %w", err)
@@ -202,12 +201,18 @@ func (s *LocalStore) Write(mdl v1.Image, tags []string, w io.Writer) error {
202201
pr = progress.NewProgressReporter(w, progress.PullMsg, layer)
203202
progressChan = pr.Updates()
204203
}
205-
if err := s.writeBlob(layer, progressChan); err != nil {
204+
205+
err := s.writeBlob(layer, progressChan)
206+
207+
if progressChan != nil {
206208
close(progressChan)
207-
return fmt.Errorf("writing blob: %w", err)
209+
if err := pr.Wait(); err != nil {
210+
fmt.Printf("reporter finished with non-fatal error: %v\n", err)
211+
}
208212
}
209-
if pr != nil {
210-
close(progressChan)
213+
214+
if err != nil {
215+
return fmt.Errorf("writing blob: %w", err)
211216
}
212217
}
213218

0 commit comments

Comments
 (0)