From fc7e8f42d7f88215d756f041ec515863b75aa3bc Mon Sep 17 00:00:00 2001 From: Gladkov Alexey Date: Wed, 30 May 2018 18:00:57 +0200 Subject: [PATCH] Fix deadlock in the inmemory storage driver According golang documentation [1]: no goroutine should expect to be able to acquire a read lock until the initial read lock is released. [1] https://golang.org/pkg/sync/#RWMutex Signed-off-by: Gladkov Alexey --- registry/storage/driver/inmemory/driver.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/registry/storage/driver/inmemory/driver.go b/registry/storage/driver/inmemory/driver.go index e18e2933..4b1f5f48 100644 --- a/registry/storage/driver/inmemory/driver.go +++ b/registry/storage/driver/inmemory/driver.go @@ -73,7 +73,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) { d.mutex.RLock() defer d.mutex.RUnlock() - rc, err := d.Reader(ctx, path, 0) + rc, err := d.reader(ctx, path, 0) if err != nil { return nil, err } @@ -108,6 +108,10 @@ func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.Read d.mutex.RLock() defer d.mutex.RUnlock() + return d.reader(ctx, path, offset) +} + +func (d *driver) reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) { if offset < 0 { return nil, storagedriver.InvalidOffsetError{Path: path, Offset: offset} }