Fix: add recycleLock preventing recycle FileSystem used by another goroutine
This commit is contained in:
parent
11c218eb94
commit
d97bc26042
3 changed files with 13 additions and 2 deletions
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 8ec4514b7690eef20b283c1f00ee2d921f19ae7d
|
Subproject commit 253bf0c5a064345af2ba4e5c3df68978de49755b
|
|
@ -97,6 +97,9 @@ type FileSystem struct {
|
||||||
文件系统处理适配器
|
文件系统处理适配器
|
||||||
*/
|
*/
|
||||||
Handler Handler
|
Handler Handler
|
||||||
|
|
||||||
|
// 回收锁
|
||||||
|
recycleLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEmptyFS 从pool中获取新的FileSystem
|
// getEmptyFS 从pool中获取新的FileSystem
|
||||||
|
@ -107,6 +110,7 @@ func getEmptyFS() *FileSystem {
|
||||||
|
|
||||||
// Recycle 回收FileSystem资源
|
// Recycle 回收FileSystem资源
|
||||||
func (fs *FileSystem) Recycle() {
|
func (fs *FileSystem) Recycle() {
|
||||||
|
fs.recycleLock.Lock()
|
||||||
fs.reset()
|
fs.reset()
|
||||||
FSPool.Put(fs)
|
FSPool.Put(fs)
|
||||||
}
|
}
|
||||||
|
@ -120,6 +124,7 @@ func (fs *FileSystem) reset() {
|
||||||
fs.Handler = nil
|
fs.Handler = nil
|
||||||
fs.Root = nil
|
fs.Root = nil
|
||||||
fs.Lock = sync.Mutex{}
|
fs.Lock = sync.Mutex{}
|
||||||
|
fs.recycleLock = sync.Mutex{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFileSystem 初始化一个文件系统
|
// NewFileSystem 初始化一个文件系统
|
||||||
|
|
|
@ -228,7 +228,9 @@ func GenericAfterUpdate(ctx context.Context, fs *FileSystem) error {
|
||||||
|
|
||||||
// 尝试清空原有缩略图并重新生成
|
// 尝试清空原有缩略图并重新生成
|
||||||
if originFile.GetPolicy().IsThumbGenerateNeeded() {
|
if originFile.GetPolicy().IsThumbGenerateNeeded() {
|
||||||
|
fs.recycleLock.Lock()
|
||||||
go func() {
|
go func() {
|
||||||
|
defer fs.recycleLock.Unlock()
|
||||||
if originFile.PicInfo != "" {
|
if originFile.PicInfo != "" {
|
||||||
_, _ = fs.Handler.Delete(ctx, []string{originFile.SourceName + conf.ThumbConfig.FileSuffix})
|
_, _ = fs.Handler.Delete(ctx, []string{originFile.SourceName + conf.ThumbConfig.FileSuffix})
|
||||||
fs.GenerateThumbnail(ctx, &originFile)
|
fs.GenerateThumbnail(ctx, &originFile)
|
||||||
|
@ -297,7 +299,11 @@ func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
|
||||||
|
|
||||||
// 异步尝试生成缩略图
|
// 异步尝试生成缩略图
|
||||||
if fs.User.Policy.IsThumbGenerateNeeded() {
|
if fs.User.Policy.IsThumbGenerateNeeded() {
|
||||||
go fs.GenerateThumbnail(ctx, file)
|
fs.recycleLock.Lock()
|
||||||
|
go func() {
|
||||||
|
defer fs.recycleLock.Unlock()
|
||||||
|
fs.GenerateThumbnail(ctx, file)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue