Skip to content

Agent Mesh

review: address PR feedback on body-close and sqlite pool scoping

Antonio Ojeaf151ac9d9903
diff --git a/internal/node/stdio_bridge.go b/internal/node/stdio_bridge.go
index 1e0a12db..dd93ed58 100644
--- a/internal/node/stdio_bridge.go
+++ b/internal/node/stdio_bridge.go
@@ -129,12 +129,12 @@ func (b *StdioBridge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
case http.MethodPost:
r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodyBytes)
+ defer func() { _ = r.Body.Close() }()
body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "Failed to read body", http.StatusInternalServerError)
return
}
- _ = r.Body.Close()
var msg map[string]any
isCall := false
diff --git a/internal/storage/sql_store.go b/internal/storage/sql_store.go
index 871520c2..ed3ad2be 100644
--- a/internal/storage/sql_store.go
+++ b/internal/storage/sql_store.go
@@ -80,12 +80,19 @@ func NewSQLStore(driverName, dataSourceName string) (*SQLStore, error) {
db.SetMaxIdleConns(5)
db.SetConnMaxLifetime(5 * time.Minute)
} else {
- // SQLite only supports a single writer at a time, and a lone
- // connection keeps ":memory:" DSNs (used by tests) consistent,
- // since each sql.DB connection to ":memory:" is otherwise its
- // own independent, empty database.
- db.SetMaxOpenConns(1)
- db.SetMaxIdleConns(1)
+ if strings.Contains(dataSourceName, ":memory:") {
+ // A lone connection keeps ":memory:" DSNs (used by tests)
+ // consistent, since each additional sql.DB connection to
+ // ":memory:" is otherwise its own independent, empty database.
+ db.SetMaxOpenConns(1)
+ db.SetMaxIdleConns(1)
+ } else {
+ // File-backed SQLite in WAL mode supports concurrent readers
+ // with a single writer, so allow a small pool instead of
+ // serializing every access through one connection.
+ db.SetMaxOpenConns(10)
+ db.SetMaxIdleConns(2)
+ }
}
store := &SQLStore{