From 3da9b14bfeaa9dfc6a368520cfbd921e8936e2d5 Mon Sep 17 00:00:00 2001 From: sagitchu Date: Fri, 3 Apr 2026 15:51:59 +0800 Subject: [PATCH] fix(backend): prevent idle transaction timeout in postgresql during tunnel update --- go-backend/internal/http/handler/mutations.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/go-backend/internal/http/handler/mutations.go b/go-backend/internal/http/handler/mutations.go index df88a2c..9db35e5 100644 --- a/go-backend/internal/http/handler/mutations.go +++ b/go-backend/internal/http/handler/mutations.go @@ -778,14 +778,7 @@ func (h *Handler) tunnelUpdate(w http.ResponseWriter, r *http.Request) { ipPreference := asString(req["ipPreference"]) localDomain := h.federationLocalDomain() - tx := h.repo.BeginTx() - if tx.Error != nil { - response.WriteJSON(w, response.Err(-2, tx.Error.Error())) - return - } - defer func() { tx.Rollback() }() - - runtimeState, err := h.prepareTunnelCreateState(tx, req, typeVal, id) + runtimeState, err := h.prepareTunnelCreateState(h.repo.DB(), req, typeVal, id) if err != nil { response.WriteJSON(w, response.ErrDefault(err.Error())) return @@ -804,6 +797,14 @@ func (h *Handler) tunnelUpdate(w http.ResponseWriter, r *http.Request) { } applyTunnelPortsToRequest(req, runtimeState) + tx := h.repo.BeginTx() + if tx.Error != nil { + h.releaseFederationRuntimeRefs(federationReleaseRefs) + response.WriteJSON(w, response.Err(-2, tx.Error.Error())) + return + } + defer func() { tx.Rollback() }() + if err := h.repo.UpdateTunnelTx( tx, id,