fix resource manager dead lock (#2302)
Co-authored-by: sado <liaoyonglin@bilibili.com>
This commit is contained in:
@@ -57,8 +57,8 @@ func (manager *ResourceManager) GetResource(key string, create func() (io.Closer
|
|||||||
}
|
}
|
||||||
|
|
||||||
manager.lock.Lock()
|
manager.lock.Lock()
|
||||||
|
defer manager.lock.Unlock()
|
||||||
manager.resources[key] = resource
|
manager.resources[key] = resource
|
||||||
manager.lock.Unlock()
|
|
||||||
|
|
||||||
return resource, nil
|
return resource, nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -74,6 +74,12 @@ func TestResourceManager_UseAfterClose(t *testing.T) {
|
|||||||
return nil, errors.New("fail")
|
return nil, errors.New("fail")
|
||||||
})
|
})
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
_, err = manager.GetResource("key", func() (io.Closer, error) {
|
||||||
|
return &dummyResource{age: 123}, nil
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user