Skip to content

Commit fee1409

Browse files
committed
add hasher mu
1 parent 0430ce9 commit fee1409

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

zboxcore/sdk/chunked_upload_process_js.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import (
3232
)
3333

3434
var (
35-
hasherMap map[string]workerProcess
35+
hasherMap map[string]workerProcess
36+
hasherMapMu sync.Mutex
3637
)
3738

3839
type workerProcess struct {
@@ -455,6 +456,7 @@ func ProcessEventData(data safejs.Value) {
455456
selfPostMessage(false, false, err.Error(), remotePath, 0, 0, 0, nil)
456457
return
457458
}
459+
hasherMapMu.Lock()
458460
wp, ok := hasherMap[fileMeta.RemotePath]
459461
if !ok {
460462
wp = workerProcess{
@@ -466,8 +468,13 @@ func ProcessEventData(data safejs.Value) {
466468
wp.hasher = CreateHasher(formInfo.ShardSize)
467469
hasherMap[fileMeta.RemotePath] = wp
468470
}
471+
hasherMapMu.Unlock()
469472
if formInfo.IsFinal {
470-
defer delete(hasherMap, fileMeta.RemotePath)
473+
defer func() {
474+
hasherMapMu.Lock()
475+
delete(hasherMap, fileMeta.RemotePath)
476+
hasherMapMu.Unlock()
477+
}()
471478
}
472479
blobberID := os.Getenv("BLOBBER_ID")
473480
formBuilder := CreateChunkedUploadFormBuilder(formInfo.StorageVersion, formInfo.EncryptionVersion, formInfo.PrivateSigningKey)

0 commit comments

Comments
 (0)