Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: concurrent counter operates (#1706)

Athurg Gooth0cea5ebaeb22
diff --git a/server/resource.go b/server/resource.go
index d59cc1054..8bf5c800f 100644
--- a/server/resource.go
+++ b/server/resource.go
@@ -13,6 +13,7 @@ import (
"regexp"
"strconv"
"strings"
+ "sync/atomic"
"time"
"github.com/disintegration/imaging"
@@ -501,7 +502,7 @@ func replacePathTemplate(path string, filename string) string {
return path
}
-var availableGeneratorAmount = 32
+var availableGeneratorAmount int32 = 32
func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error) {
if _, err := os.Stat(dstPath); err != nil {
@@ -509,12 +510,12 @@ func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error)
return nil, errors.Wrap(err, "failed to check thumbnail image stat")
}
- if availableGeneratorAmount <= 0 {
+ if atomic.LoadInt32(&availableGeneratorAmount) <= 0 {
return nil, errors.New("not enough available generator amount")
}
- availableGeneratorAmount--
+ atomic.AddInt32(&availableGeneratorAmount, -1)
defer func() {
- availableGeneratorAmount++
+ atomic.AddInt32(&availableGeneratorAmount, 1)
}()
reader := bytes.NewReader(srcBlob)