Skip to content

Commit 2da97e1

Browse files
committed
Close tar stdout pipe before Wait to prevent hang on write failure
1 parent 506d6c1 commit 2da97e1

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

cmd/gradle-cache/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,10 @@ func createTarZstd(ctx context.Context, w io.Writer, sources []tarSource) error
955955

956956
_, copyErr := io.Copy(enc, tarStdout)
957957
encErr := enc.Close()
958+
// Close the pipe so tar sees EOF on its stdout and exits cleanly.
959+
// Without this, if copyErr or encErr is non-nil, tar may block
960+
// forever writing to a full pipe and tarCmd.Wait() will hang.
961+
tarStdout.Close() //nolint:errcheck,gosec
958962
tarErr := tarCmd.Wait()
959963

960964
var errs []error

0 commit comments

Comments
 (0)