Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 70b9bad

Browse files
committed
Ensure ArchiveAsync methods don't return until the input channel is closed.
Having the ArciveAsync methods return after an error causes a potential deadlock as users send into the jobs channel but there is no goroutine listening.
1 parent 4087add commit 70b9bad

File tree

3 files changed

+3
-20
lines changed

3 files changed

+3
-20
lines changed

interfaces.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ type ArchiverAsync interface {
7777
// the files for the archive. Close the files channel after
7878
// all the files have been sent.
7979
//
80-
// This won't return until either an error has been reported
81-
// (if not using ContinueOnError) or the channel is closed.
80+
// This won't return until the channel is closed.
8281
ArchiveAsync(ctx context.Context, output io.Writer, files <-chan ArchiveAsyncJob) error
8382
}
8483

tar.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,7 @@ func (t Tar) ArchiveAsync(ctx context.Context, output io.Writer, jobs <-chan Arc
6363
defer tw.Close()
6464

6565
for job := range jobs {
66-
err := t.writeFileToArchive(ctx, tw, job.File)
67-
job.Result <- err
68-
if err != nil {
69-
if t.ContinueOnError && ctx.Err() == nil { // context errors should always abort
70-
log.Printf("[ERROR] %v", err)
71-
continue
72-
}
73-
return err
74-
}
66+
job.Result <- t.writeFileToArchive(ctx, tw, job.File)
7567
}
7668

7769
return nil

zip.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,7 @@ func (z Zip) ArchiveAsync(ctx context.Context, output io.Writer, jobs <-chan Arc
120120

121121
var i int
122122
for job := range jobs {
123-
err := z.archiveOneFile(ctx, zw, i, job.File)
124-
job.Result <- err
125-
if err != nil {
126-
if z.ContinueOnError && ctx.Err() == nil { // context errors should always abort
127-
log.Printf("[ERROR] %v", err)
128-
continue
129-
}
130-
return err
131-
}
123+
job.Result <- z.archiveOneFile(ctx, zw, i, job.File)
132124
i++
133125
}
134126

0 commit comments

Comments
 (0)