Skip to content

Commit

Permalink
fix(storage): fix Writer.ChunkSize validation
Browse files Browse the repository at this point in the history
Since w.opened is set to true before this validation currently,
subsequent calls to Writer.Close will deadlock. There is no
reason not to do this check first before opening the pipe.

Thanks to @dt for pointing this out.

Updates googleapis#4167
  • Loading branch information
tritone committed Jun 14, 2021
1 parent 64dc099 commit 4ea45f1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions storage/writer.go
Expand Up @@ -99,15 +99,15 @@ func (w *Writer) open() error {
if attrs.KMSKeyName != "" && w.o.encryptionKey != nil {
return errors.New("storage: cannot use KMSKeyName with a customer-supplied encryption key")
}
if w.ChunkSize < 0 {
return errors.New("storage: Writer.ChunkSize must be non-negative")
}
pr, pw := io.Pipe()
w.pw = pw
w.opened = true

go w.monitorCancel()

if w.ChunkSize < 0 {
return errors.New("storage: Writer.ChunkSize must be non-negative")
}
mediaOpts := []googleapi.MediaOption{
googleapi.ChunkSize(w.ChunkSize),
}
Expand Down

0 comments on commit 4ea45f1

Please sign in to comment.