mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-05 17:46:37 +08:00
fix: prevent idle transaction timeout in postgresql during tunnel update (#404)
## Summary - Moved `tx := h.repo.BeginTx()` below `applyFederationRuntime` in `tunnelUpdate` - This prevents the database transaction from remaining idle for an extended period of time while making HTTP network requests to federation nodes, which can trigger the `idle_in_transaction_session_timeout` or cause connection pool exhaustion in PostgreSQL. ## Test Plan - [x] Backend tests passed (`go test ./...`) - [ ] Verify tunnel updates no longer timeout with PostgreSQL
This commit is contained in:
@@ -778,14 +778,7 @@ func (h *Handler) tunnelUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
ipPreference := asString(req["ipPreference"])
|
ipPreference := asString(req["ipPreference"])
|
||||||
localDomain := h.federationLocalDomain()
|
localDomain := h.federationLocalDomain()
|
||||||
|
|
||||||
tx := h.repo.BeginTx()
|
runtimeState, err := h.prepareTunnelCreateState(h.repo.DB(), req, typeVal, id)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteJSON(w, response.ErrDefault(err.Error()))
|
response.WriteJSON(w, response.ErrDefault(err.Error()))
|
||||||
return
|
return
|
||||||
@@ -804,6 +797,14 @@ func (h *Handler) tunnelUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
applyTunnelPortsToRequest(req, runtimeState)
|
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(
|
if err := h.repo.UpdateTunnelTx(
|
||||||
tx,
|
tx,
|
||||||
id,
|
id,
|
||||||
|
|||||||
Reference in New Issue
Block a user