Fix: add recycleLock preventing recycle FileSystem used by another goroutine

pull/640/head
HFO4 4 years ago
parent 11c218eb94
commit d97bc26042

@ -1 +1 @@
Subproject commit 8ec4514b7690eef20b283c1f00ee2d921f19ae7d
Subproject commit 253bf0c5a064345af2ba4e5c3df68978de49755b

@ -97,6 +97,9 @@ type FileSystem struct {
*/
Handler Handler
// 回收锁
recycleLock sync.Mutex
}
// getEmptyFS 从pool中获取新的FileSystem
@ -107,6 +110,7 @@ func getEmptyFS() *FileSystem {
// Recycle 回收FileSystem资源
func (fs *FileSystem) Recycle() {
fs.recycleLock.Lock()
fs.reset()
FSPool.Put(fs)
}
@ -120,6 +124,7 @@ func (fs *FileSystem) reset() {
fs.Handler = nil
fs.Root = nil
fs.Lock = sync.Mutex{}
fs.recycleLock = sync.Mutex{}
}
// NewFileSystem 初始化一个文件系统

@ -228,7 +228,9 @@ func GenericAfterUpdate(ctx context.Context, fs *FileSystem) error {
// 尝试清空原有缩略图并重新生成
if originFile.GetPolicy().IsThumbGenerateNeeded() {
fs.recycleLock.Lock()
go func() {
defer fs.recycleLock.Unlock()
if originFile.PicInfo != "" {
_, _ = fs.Handler.Delete(ctx, []string{originFile.SourceName + conf.ThumbConfig.FileSuffix})
fs.GenerateThumbnail(ctx, &originFile)
@ -297,7 +299,11 @@ func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
// 异步尝试生成缩略图
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

Loading…
Cancel
Save