From 6a2a075c1400e1889c6b37e5a74279e020bc5460 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 19 Jun 2019 10:43:26 +0100 Subject: [PATCH] fs/cache: fix locking This was causing `fatal error: sync: unlock of unlocked mutex` if a panic ocurred in fsNewFs. --- fs/cache/cache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/cache/cache.go b/fs/cache/cache.go index 569209834..65a1fd52e 100644 --- a/fs/cache/cache.go +++ b/fs/cache/cache.go @@ -27,12 +27,10 @@ type cacheEntry struct { // Get gets a fs.Fs named fsString either from the cache or creates it afresh func Get(fsString string) (f fs.Fs, err error) { fsCacheMu.Lock() - defer fsCacheMu.Unlock() entry, ok := fsCache[fsString] if !ok { fsCacheMu.Unlock() // Unlock in case Get is called recursively f, err = fsNewFs(fsString) - fsCacheMu.Lock() if err != nil && err != fs.ErrorIsFile { return f, err } @@ -41,8 +39,10 @@ func Get(fsString string) (f fs.Fs, err error) { fsString: fsString, err: err, } + fsCacheMu.Lock() fsCache[fsString] = entry } + defer fsCacheMu.Unlock() entry.lastUsed = time.Now() if !expireRunning { time.AfterFunc(cacheExpireInterval, cacheExpire)