Skip to content
Permalink
Browse files
fix(storage): fix Writer.ChunkSize validation (#4255)
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 #4167
  • Loading branch information
tritone committed Jun 14, 2021
1 parent f9db3e9 commit 69c2e9dc6303e1a004d3104a8178532fa738e742
Showing with 3 additions and 3 deletions.
  1. +3 −3 storage/writer.go
@@ -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),
}

0 comments on commit 69c2e9d

Please sign in to comment.