mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 01:32:33 +02:00
Fix SQLite queue
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -18,6 +18,10 @@ func Open(path string) (*DB, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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}
|
d := &DB{conn: conn, path: path}
|
||||||
if err := d.migrate(); err != nil {
|
if err := d.migrate(); err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|||||||
@@ -195,17 +195,19 @@ func (b *Broker) SaveEntry(f *proxy.Flow) {
|
|||||||
if config.Global.History.SkipDuplicates {
|
if config.Global.History.SkipDuplicates {
|
||||||
var dup bool
|
var dup bool
|
||||||
entry, dup, err = d.InsertIfNotDuplicate(pending, body)
|
entry, dup, err = d.InsertIfNotDuplicate(pending, body)
|
||||||
if dup || err != nil {
|
if dup {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entry, err = d.InsertEntry(pending, body)
|
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 {
|
if cb := b.onNewEntry; cb != nil {
|
||||||
go cb(entry)
|
go cb(entry)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Broker) Decide(p *PendingRequest, d Decision) {
|
func (b *Broker) Decide(p *PendingRequest, d Decision) {
|
||||||
|
|||||||
Reference in New Issue
Block a user