Skip to content

Commit

Permalink
Stop swallowing writer errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBaulch committed Jan 17, 2025
1 parent 9750344 commit 2bb6221
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend/s3/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type File struct {
s3Writer *io.PipeWriter
cancelFunc context.CancelFunc
writeCalled bool
s3WriterCompleteCh chan struct{}
s3WriterCompleteCh chan error
}

// Info Functions
Expand Down Expand Up @@ -301,9 +301,12 @@ func (f *File) Close() error { //nolint:gocyclo
// read s3WriterCompleteCh if it exists
if f.writeCalled && f.s3Writer != nil && f.s3WriterCompleteCh != nil {
// wait for s3Writer to complete
<-f.s3WriterCompleteCh
err := <-f.s3WriterCompleteCh
// close s3WriterCompleteCh channel
close(f.s3WriterCompleteCh)
if err != nil {
return utils.WrapCloseError(err)
}
}
err := waitUntilFileExists(f, 5)
if err != nil {
Expand Down Expand Up @@ -814,7 +817,7 @@ func (f *File) initWriters() error {
}

func (f *File) getS3Writer() (*io.PipeWriter, error) {
f.s3WriterCompleteCh = make(chan struct{}, 1)
f.s3WriterCompleteCh = make(chan error, 1)
pr, pw := io.Pipe()

client, err := f.fileSystem.Client()
Expand All @@ -833,7 +836,7 @@ func (f *File) getS3Writer() (*io.PipeWriter, error) {
if err != nil {
_ = pw.CloseWithError(err)
}
f.s3WriterCompleteCh <- struct{}{}
f.s3WriterCompleteCh <- err
}(uploadInput)

return pw, nil
Expand Down

0 comments on commit 2bb6221

Please sign in to comment.