From 83d8e01c816608a591d7d265e165d33c67f052be Mon Sep 17 00:00:00 2001 From: poornas Date: Wed, 10 Oct 2018 23:01:24 -0700 Subject: [PATCH] fix: Close cacheReader if cache entry has expired (#6610) prevent locking issues Fixes #6602 --- cmd/disk-cache.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index 298b47d99..9de9581e1 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -215,12 +215,11 @@ func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string, // If the backend is down, serve the request from cache. return cacheReader, nil } - if cacheReader.ObjInfo.ETag == objInfo.ETag && !isStaleCache(objInfo) { // Object is not stale, so serve from cache return cacheReader, nil } - + cacheReader.Close() // Object is stale, so delete from cache dcache.Delete(ctx, bucket, object) } @@ -969,6 +968,9 @@ func newServerCacheObjects(config CacheConfig) (CacheObjectLayer, error) { GetObjectInfoFn: func(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) { return newObjectLayerFn().GetObjectInfo(ctx, bucket, object, opts) }, + GetObjectNInfoFn: func(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (gr *GetObjectReader, err error) { + return newObjectLayerFn().GetObjectNInfo(ctx, bucket, object, rs, h, lockType, opts) + }, PutObjectFn: func(ctx context.Context, bucket, object string, data *hash.Reader, metadata map[string]string, opts ObjectOptions) (objInfo ObjectInfo, err error) { return newObjectLayerFn().PutObject(ctx, bucket, object, data, metadata, opts) },