This is an automated email from the ASF dual-hosted git repository.

LinkinStars pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer-plugins.git

commit 7d683296fd9779b9655790eddc32e7ce47670fb9
Author: hgaol <[email protected]>
AuthorDate: Wed Jul 8 14:05:50 2026 +0000

    fix(vector-search): guard syncing flag with mutex to prevent data race
    
    The syncing flag was read outside the mutex before launching the sync
    goroutine, and re-checked after the goroutine had already reset it. This
    was a data race and could allow a redundant full sync to start. Claim the
    flag under the lock synchronously before spawning the goroutine, and reset
    it under the lock on exit.
---
 vector-search-chromadb/sync.go      | 16 +++++++++-------
 vector-search-elasticsearch/sync.go | 16 +++++++++-------
 vector-search-milvus/sync.go        | 16 +++++++++-------
 vector-search-pgvector/sync.go      | 16 +++++++++-------
 vector-search-qdrant/sync.go        | 16 +++++++++-------
 vector-search-weaviate/sync.go      | 16 +++++++++-------
 6 files changed, 54 insertions(+), 42 deletions(-)

diff --git a/vector-search-chromadb/sync.go b/vector-search-chromadb/sync.go
index 14fe5c8..0666b71 100644
--- a/vector-search-chromadb/sync.go
+++ b/vector-search-chromadb/sync.go
@@ -31,19 +31,21 @@ func (e *VectorSearchEngine) sync() {
                log.Warn("chromadb: syncer not registered, skip sync")
                return
        }
+       e.lock.Lock()
        if e.syncing {
+               e.lock.Unlock()
                log.Warn("chromadb: sync already running, skip")
                return
        }
+       e.syncing = true
+       e.lock.Unlock()
 
        go func() {
-               e.lock.Lock()
-               defer e.lock.Unlock()
-               if e.syncing {
-                       return
-               }
-               e.syncing = true
-               defer func() { e.syncing = false }()
+               defer func() {
+                       e.lock.Lock()
+                       e.syncing = false
+                       e.lock.Unlock()
+               }()
 
                page, pageSize := 1, 100
 
diff --git a/vector-search-elasticsearch/sync.go 
b/vector-search-elasticsearch/sync.go
index f6a8f1c..d132342 100644
--- a/vector-search-elasticsearch/sync.go
+++ b/vector-search-elasticsearch/sync.go
@@ -33,19 +33,21 @@ func (e *VectorSearchEngine) sync() {
                log.Warn("es-vector: syncer not registered, skip sync")
                return
        }
+       e.lock.Lock()
        if e.syncing {
+               e.lock.Unlock()
                log.Warn("es-vector: sync already running, skip")
                return
        }
+       e.syncing = true
+       e.lock.Unlock()
 
        go func() {
-               e.lock.Lock()
-               defer e.lock.Unlock()
-               if e.syncing {
-                       return
-               }
-               e.syncing = true
-               defer func() { e.syncing = false }()
+               defer func() {
+                       e.lock.Lock()
+                       e.syncing = false
+                       e.lock.Unlock()
+               }()
 
                page, pageSize := 1, 100
 
diff --git a/vector-search-milvus/sync.go b/vector-search-milvus/sync.go
index 8962653..df5b28d 100644
--- a/vector-search-milvus/sync.go
+++ b/vector-search-milvus/sync.go
@@ -31,19 +31,21 @@ func (e *VectorSearchEngine) sync() {
                log.Warn("milvus: syncer not registered, skip sync")
                return
        }
+       e.lock.Lock()
        if e.syncing {
+               e.lock.Unlock()
                log.Warn("milvus: sync already running, skip")
                return
        }
+       e.syncing = true
+       e.lock.Unlock()
 
        go func() {
-               e.lock.Lock()
-               defer e.lock.Unlock()
-               if e.syncing {
-                       return
-               }
-               e.syncing = true
-               defer func() { e.syncing = false }()
+               defer func() {
+                       e.lock.Lock()
+                       e.syncing = false
+                       e.lock.Unlock()
+               }()
 
                page, pageSize := 1, 100
 
diff --git a/vector-search-pgvector/sync.go b/vector-search-pgvector/sync.go
index e4a3063..c88c3c6 100644
--- a/vector-search-pgvector/sync.go
+++ b/vector-search-pgvector/sync.go
@@ -33,19 +33,21 @@ func (e *VectorSearchEngine) sync() {
                log.Warn("pgvector: syncer not registered, skip sync")
                return
        }
+       e.lock.Lock()
        if e.syncing {
+               e.lock.Unlock()
                log.Warn("pgvector: sync already running, skip")
                return
        }
+       e.syncing = true
+       e.lock.Unlock()
 
        go func() {
-               e.lock.Lock()
-               defer e.lock.Unlock()
-               if e.syncing {
-                       return
-               }
-               e.syncing = true
-               defer func() { e.syncing = false }()
+               defer func() {
+                       e.lock.Lock()
+                       e.syncing = false
+                       e.lock.Unlock()
+               }()
 
                page, pageSize := 1, 100
 
diff --git a/vector-search-qdrant/sync.go b/vector-search-qdrant/sync.go
index 18ba990..8998093 100644
--- a/vector-search-qdrant/sync.go
+++ b/vector-search-qdrant/sync.go
@@ -31,19 +31,21 @@ func (e *VectorSearchEngine) sync() {
                log.Warn("qdrant: syncer not registered, skip sync")
                return
        }
+       e.lock.Lock()
        if e.syncing {
+               e.lock.Unlock()
                log.Warn("qdrant: sync already running, skip")
                return
        }
+       e.syncing = true
+       e.lock.Unlock()
 
        go func() {
-               e.lock.Lock()
-               defer e.lock.Unlock()
-               if e.syncing {
-                       return
-               }
-               e.syncing = true
-               defer func() { e.syncing = false }()
+               defer func() {
+                       e.lock.Lock()
+                       e.syncing = false
+                       e.lock.Unlock()
+               }()
 
                page, pageSize := 1, 100
 
diff --git a/vector-search-weaviate/sync.go b/vector-search-weaviate/sync.go
index 4e3b851..399779d 100644
--- a/vector-search-weaviate/sync.go
+++ b/vector-search-weaviate/sync.go
@@ -33,19 +33,21 @@ func (e *VectorSearchEngine) sync() {
                log.Warn("weaviate: syncer not registered, skip sync")
                return
        }
+       e.lock.Lock()
        if e.syncing {
+               e.lock.Unlock()
                log.Warn("weaviate: sync already running, skip")
                return
        }
+       e.syncing = true
+       e.lock.Unlock()
 
        go func() {
-               e.lock.Lock()
-               defer e.lock.Unlock()
-               if e.syncing {
-                       return
-               }
-               e.syncing = true
-               defer func() { e.syncing = false }()
+               defer func() {
+                       e.lock.Lock()
+                       e.syncing = false
+                       e.lock.Unlock()
+               }()
 
                page, pageSize := 1, 100
 

Reply via email to