Fix SQLite queue

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-05-19 15:05:46 +02:00
parent 28b070dafc
commit 598455f8d3
2 changed files with 11 additions and 5 deletions
+4
View File
@@ -18,6 +18,10 @@ func Open(path string) (*DB, error) {
if err != nil {
return nil, err
}
// SQLite only supports one concurrent writer; a pool of connections would
// cause SQLITE_BUSY errors when multiple proxy goroutines try to insert
// history entries at the same time.
conn.SetMaxOpenConns(1)
d := &DB{conn: conn, path: path}
if err := d.migrate(); err != nil {
conn.Close()
+5 -3
View File
@@ -195,18 +195,20 @@ func (b *Broker) SaveEntry(f *proxy.Flow) {
if config.Global.History.SkipDuplicates {
var dup bool
entry, dup, err = d.InsertIfNotDuplicate(pending, body)
if dup || err != nil {
if dup {
return
}
} else {
entry, err = d.InsertEntry(pending, body)
}
if err == nil {
if err != nil {
log.Printf("intercept: failed to save history entry: %v", err)
return
}
if cb := b.onNewEntry; cb != nil {
go cb(entry)
}
}
}
func (b *Broker) Decide(p *PendingRequest, d Decision) {
p.decision <- d