fix: SQLite WAL mode + log all swallowed 500 errors
- internal/db/db.go: Use _pragma syntax so modernc.org/sqlite actually applies busy_timeout(5000) and journal_mode(WAL). Eliminates SQLITE_BUSY 500s when concurrent reads hit a writer holding the DELETE-mode lock. - internal/api/handlers_*.go: Add slog.Error before every writeError with StatusInternalServerError so real errors appear in logs (30+ sites across handlers_jobs, handlers_machines, handlers_syncpairs, handlers_sshkeys).
This commit is contained in:
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -25,6 +26,7 @@ func (h *SyncPairHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
repo := models.NewSyncPairRepository(h.db)
|
||||
pairs, err := repo.GetAll()
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch sync pairs", "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch sync pairs")
|
||||
return
|
||||
}
|
||||
@@ -48,6 +50,7 @@ func (h *SyncPairHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch sync pair", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch sync pair")
|
||||
return
|
||||
}
|
||||
@@ -94,6 +97,7 @@ func (h *SyncPairHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
repo := models.NewSyncPairRepository(h.db)
|
||||
id, err := repo.Create(sp)
|
||||
if err != nil {
|
||||
slog.Error("failed to create sync pair", "name", req.Name, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to create sync pair")
|
||||
return
|
||||
}
|
||||
@@ -131,6 +135,7 @@ func (h *SyncPairHandler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch sync pair", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch sync pair")
|
||||
return
|
||||
}
|
||||
@@ -146,6 +151,7 @@ func (h *SyncPairHandler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
existing.Enabled = req.Enabled
|
||||
|
||||
if err := repo.Update(existing); err != nil {
|
||||
slog.Error("failed to update sync pair", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to update sync pair")
|
||||
return
|
||||
}
|
||||
@@ -161,6 +167,7 @@ func (h *SyncPairHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
repo := models.NewSyncPairRepository(h.db)
|
||||
if err := repo.Delete(id); err != nil {
|
||||
slog.Error("failed to delete sync pair", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to delete sync pair")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user