源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package storesqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
sqlitedriver "modernc.org/sqlite"
|
||||
sqlite3 "modernc.org/sqlite/lib"
|
||||
)
|
||||
|
||||
// A busy result means that the transaction did not commit and is safe to
|
||||
// replay from its beginning. Keep the retry deliberately small: it smooths
|
||||
// transient WAL/checkpoint contention without hiding a second process that
|
||||
// owns the database for an unbounded period.
|
||||
const sqliteBusyRetryAttempts = 3
|
||||
const sqliteBusyRetryBudget = 5 * time.Second
|
||||
|
||||
var sqliteBusyRetryBackoff = [...]time.Duration{
|
||||
50 * time.Millisecond,
|
||||
100 * time.Millisecond,
|
||||
}
|
||||
|
||||
func isSQLiteBusyError(err error) bool {
|
||||
var sqliteErr *sqlitedriver.Error
|
||||
return errors.As(err, &sqliteErr) && sqliteErr.Code()&0xff == sqlite3.SQLITE_BUSY
|
||||
}
|
||||
|
||||
func retrySQLiteBusy(ctx context.Context, operation func(context.Context) error) error {
|
||||
retryCtx, cancel := context.WithTimeout(ctx, sqliteBusyRetryBudget)
|
||||
defer cancel()
|
||||
|
||||
for attempt := 1; attempt <= sqliteBusyRetryAttempts; attempt++ {
|
||||
err := operation(retryCtx)
|
||||
if err == nil || !isSQLiteBusyError(err) || attempt == sqliteBusyRetryAttempts {
|
||||
return err
|
||||
}
|
||||
if err := waitSQLiteBusyRetry(retryCtx, sqliteBusyRetryBackoff[attempt-1]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func waitSQLiteBusyRetry(ctx context.Context, delay time.Duration) error {
|
||||
timer := time.NewTimer(delay)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-timer.C:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user