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:
@@ -30,6 +30,7 @@ func (h *MachineHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
repo := models.NewMachineRepository(h.db)
|
||||
ms, err := repo.GetAll()
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch machines", "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch machines")
|
||||
return
|
||||
}
|
||||
@@ -53,6 +54,7 @@ func (h *MachineHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch machine", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch machine")
|
||||
return
|
||||
}
|
||||
@@ -106,6 +108,7 @@ func (h *MachineHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
repo := models.NewMachineRepository(h.db)
|
||||
id, err := repo.Create(m)
|
||||
if err != nil {
|
||||
slog.Error("failed to create machine", "name", req.Name, "host", req.Host, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to create machine")
|
||||
return
|
||||
}
|
||||
@@ -150,6 +153,7 @@ func (h *MachineHandler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch machine", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch machine")
|
||||
return
|
||||
}
|
||||
@@ -170,6 +174,7 @@ func (h *MachineHandler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := repo.Update(existing); err != nil {
|
||||
slog.Error("failed to update machine", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to update machine")
|
||||
return
|
||||
}
|
||||
@@ -189,6 +194,7 @@ func (h *MachineHandler) TestWoL(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch machine", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch machine")
|
||||
return
|
||||
}
|
||||
@@ -238,6 +244,7 @@ func (h *MachineHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
repo := models.NewMachineRepository(h.db)
|
||||
if err := repo.Delete(id); err != nil {
|
||||
slog.Error("failed to delete machine", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to delete machine")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user