Skip to content

bug: transaction has already been committed or rolled back on every UPDATE via RestHeadSpec. #20

Description

@warkanum

Bug: sql: transaction has already been committed or rolled back on every UPDATE via RestHeadSpec.

Where: github.com/bitechdev/ResolveSpec v1.1.26, pkg/restheadspec/handler.go, handleUpdate, around lines 1494–1506.

What's happening:
Where: github.com/bitechdev/ResolveSpec v1.1.26, pkg/restheadspec/handler.go, handleUpdate, around lines 1494–1506.

What's happening:

  1. Line 1460: hookCtx.Tx = tx is set inside the transaction, and BeforeScan runs fine (this is where setUserViaContext calls core.c_setuserid successfully against the live tx).
  2. Line 1486: the transaction closure returns, RunInTransaction commits and returns.
  3. Lines 1494–1509 (post-commit): a new selectQuery is built against h.db (correctly, the pool) to re-fetch the updated row. hookCtx.Query is updated to this new query (line 1501), but hookCtx.Tx is never reset — it still points at the now-committed tx from step 1.
  4. h.hooks.Execute(BeforeScan, hookCtx) runs again at line 1502, and the setUserViaContext hook (registered in GoCore's pkg/webserver2/resolvespec.go:44-54, WithHeaderSpec) calls tx.Exec(ctx, "select core.c_setuserid(...)", ...) on the dead transaction — producing exactly the error you saw, 3 times (once per retry/log line) plus the hook-failure logs.

Fix: add one line before line 1501:
hookCtx.Tx = h.db // reset to the pooled connection now that the transaction has committed
hookCtx.Query = selectQuery

Worth also checking handleCreate and handleDelete in the same file for the identical stale-hookCtx.Tx-reuse pattern after their transactions commit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions