This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch release-v0.19
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.19 by this push:
new bd002013c fix: ReloadBlueprints is not safe (#6331) (#6332)
bd002013c is described below
commit bd002013c26255692ec363e611556f9ee8cb04ef
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Oct 25 04:43:01 2023 -0500
fix: ReloadBlueprints is not safe (#6331) (#6332)
Co-authored-by: Klesh Wong <[email protected]>
---
backend/helpers/dbhelper/txhelper.go | 5 +++--
backend/server/services/blueprint.go | 10 +++++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/backend/helpers/dbhelper/txhelper.go
b/backend/helpers/dbhelper/txhelper.go
index a7da084d4..c9101f4ec 100644
--- a/backend/helpers/dbhelper/txhelper.go
+++ b/backend/helpers/dbhelper/txhelper.go
@@ -19,9 +19,10 @@ package dbhelper
import (
"fmt"
- "github.com/apache/incubator-devlake/core/log"
"time"
+ "github.com/apache/incubator-devlake/core/log"
+
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
@@ -46,7 +47,7 @@ func (l *TxHelper[E]) Begin() dal.Transaction {
// LockTablesTimeout locks tables with timeout
func (l *TxHelper[E]) LockTablesTimeout(timeout time.Duration, lockTables
dal.LockTables) errors.Error {
- l.logger.Warn(fmt.Errorf("timeout"), "local tables")
+ l.logger.Info("try locking tables with timeout %v", timeout)
c := make(chan errors.Error, 1)
go func() {
c <- l.tx.LockTables(lockTables)
diff --git a/backend/server/services/blueprint.go
b/backend/server/services/blueprint.go
index 29aa62631..3ed9d6610 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"strings"
+ "sync"
"github.com/apache/incubator-devlake/helpers/pluginhelper/services"
@@ -233,8 +234,15 @@ func DeleteBlueprint(id uint64) errors.Error {
return nil
}
+var blueprintReloadLock sync.Mutex
+
// ReloadBlueprints FIXME ...
-func ReloadBlueprints(c *cron.Cron) errors.Error {
+func ReloadBlueprints(c *cron.Cron) (err errors.Error) {
+ // preventing concurrent reloads. It would be better to use Table Lock
, however, it requires massive refactor
+ // like the `bpManager` must accept transaction. Use mutex as a
temporary fix.
+ blueprintReloadLock.Lock()
+ defer blueprintReloadLock.Unlock()
+
enable := true
isManual := false
blueprints, _, err :=
bpManager.GetDbBlueprints(&services.GetBlueprintQuery{