1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

fix: do not immediately close the db after opening it

This commit is contained in:
Kwonunn 2025-03-24 10:17:04 +01:00
parent 187e1df52c
commit 639b83c26c

View file

@ -387,19 +387,21 @@ func (h *Handler) get(w http.ResponseWriter, r *http.Request, params httprouter.
}
cache := &Cache{}
db, err := h.openDB()
if err != nil {
h.responseJSON(w, r, 500, fmt.Errorf("cache openDB: %w", err))
return
}
db.Close()
if err := db.Get(id, cache); err != nil {
if errors.Is(err, bolthold.ErrNotFound) {
h.responseJSON(w, r, 404, fmt.Errorf("cache %d: not reserved", id))
{
db, err := h.openDB()
if err != nil {
h.responseJSON(w, r, 500, fmt.Errorf("cache openDB: %w", err))
return
}
defer db.Close()
if err := db.Get(id, cache); err != nil {
if errors.Is(err, bolthold.ErrNotFound) {
h.responseJSON(w, r, 404, fmt.Errorf("cache %d: not reserved", id))
return
}
h.responseJSON(w, r, 500, fmt.Errorf("cache Get: %w", err))
return
}
h.responseJSON(w, r, 500, fmt.Errorf("cache Get: %w", err))
return
}
// Should not happen