mirror of
https://github.com/distribution/distribution
synced 2024-11-06 19:35:52 +01:00
Release lock during WriteStream for inmemory driver
While reading from the input in WriteStream, the inmemory driver can deadlock if the reader is from the same instance. To fix this, the write lock is released before reading into a local buffer. The lock is re-acquired to finish the actual write. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
09522d8535
commit
75c5916dde
@ -133,6 +133,11 @@ func (d *Driver) WriteStream(path string, offset int64, reader io.Reader) (nn in
|
||||
return 0, fmt.Errorf("not a file")
|
||||
}
|
||||
|
||||
// Unlock while we are reading from the source, in case we are reading
|
||||
// from the same mfs instance. This can be fixed by a more granular
|
||||
// locking model.
|
||||
d.mutex.Unlock()
|
||||
d.mutex.RLock() // Take the readlock to block other writers.
|
||||
var buf bytes.Buffer
|
||||
|
||||
nn, err = buf.ReadFrom(reader)
|
||||
@ -142,9 +147,13 @@ func (d *Driver) WriteStream(path string, offset int64, reader io.Reader) (nn in
|
||||
// backend. What is the correct return value? Really, the caller needs
|
||||
// to know that the reader has been advanced and reattempting the
|
||||
// operation is incorrect.
|
||||
d.mutex.RUnlock()
|
||||
d.mutex.Lock()
|
||||
return nn, err
|
||||
}
|
||||
|
||||
d.mutex.RUnlock()
|
||||
d.mutex.Lock()
|
||||
f.WriteAt(buf.Bytes(), offset)
|
||||
return nn, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user