Преглед изворни кода

drop the current transaction on failure, to avoid being locked in bad state

Thibault bui Koechlin пре 5 година
родитељ
комит
a7babadf36
1 измењених фајлова са 1 додато и 8 уклоњено
  1. 1 8
      pkg/sqlite/commit.go

+ 1 - 8
pkg/sqlite/commit.go

@@ -5,8 +5,6 @@ import (
 	"sync/atomic"
 	"sync/atomic"
 	"time"
 	"time"
 
 
-	sqlite3 "github.com/mattn/go-sqlite3"
-
 	"github.com/crowdsecurity/crowdsec/pkg/types"
 	"github.com/crowdsecurity/crowdsec/pkg/types"
 	log "github.com/sirupsen/logrus"
 	log "github.com/sirupsen/logrus"
 )
 )
@@ -16,13 +14,8 @@ func (c *Context) Flush() error {
 	defer c.lock.Unlock()
 	defer c.lock.Unlock()
 
 
 	ret := c.tx.Commit()
 	ret := c.tx.Commit()
+
 	if ret.Error != nil {
 	if ret.Error != nil {
-		/*if the database is locked, don't overwrite the current transaction*/
-		if ret.Error == sqlite3.ErrLocked {
-			log.Errorf("sqlite commit : db is locked : %s", ret.Error)
-			return ret.Error
-		}
-		/*if it's another error, create a new transaction to avoid locking ourselves in a bad state ?*/
 		c.tx = c.Db.Begin()
 		c.tx = c.Db.Begin()
 		return fmt.Errorf("failed to commit records : %v", ret.Error)
 		return fmt.Errorf("failed to commit records : %v", ret.Error)
 	}
 	}