fix(tx): run restheadspec AfterRead in a second short transaction

This commit is contained in:
2026-09-30 22:53:07 +02:00
parent 6b6f540ab0
commit 3b93802a25
2 changed files with 67 additions and 3 deletions
+5 -3
View File
@@ -1000,12 +1000,14 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
logger.Debug("FetchRowNumber: Row number %d set in metadata", *fetchedRowNumber)
}
// Execute AfterRead hooks (runs after the transaction commits, against the pooled db)
hookCtx.Tx = h.db
// Execute AfterRead hooks in a second short transaction: the read tx has
// already committed, and hooks must never get the pooled connection.
hookCtx.Result = modelPtr
hookCtx.Error = nil
if err := h.hooks.Execute(AfterRead, hookCtx); err != nil {
if err := h.runInTx(ctx, hookCtx, func(common.Database) error {
return h.hooks.Execute(AfterRead, hookCtx)
}); err != nil {
logger.Error("AfterRead hook failed: %v", err)
h.sendError(w, http.StatusInternalServerError, "hook_error", "Hook execution failed", err)
return