From 598455f8d39ad54f4cd2d0bcb01570875d2a65a0 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Tue, 19 May 2026 15:05:46 +0200 Subject: [PATCH] Fix SQLite queue Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com> --- internal/db/db.go | 4 ++++ internal/intercept/broker.go | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/db/db.go b/internal/db/db.go index ff505d6..8052b25 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -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() diff --git a/internal/intercept/broker.go b/internal/intercept/broker.go index 2341fc3..08073ec 100644 --- a/internal/intercept/broker.go +++ b/internal/intercept/broker.go @@ -195,16 +195,18 @@ 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 cb := b.onNewEntry; cb != nil { - go cb(entry) - } + if err != nil { + log.Printf("intercept: failed to save history entry: %v", err) + return + } + if cb := b.onNewEntry; cb != nil { + go cb(entry) } }