Skip to content
Snippets Groups Projects

Code monitors: fix transaction rollbacks

Created by: camdencheek

This is a fun one.

I was seeing an issue where, when I create a code monitor, even if it failed, the monitor would still be created. We supposedly have transactional semantics in the creation code, so the transaction should be rolled back if there is a failure, but apparently that wasn't happening. Scary :ghost:

Turns out the issue was that err was being declared in the function body, and the defer func() { err = tx.Done(err) } was referring to that declared err variable. This would be fine, except we make a new scope on line 150, which makes the declaration on line 151 create a new variable. This means when we assign to it, we aren't assigning to the variable that is being read by tx.Done().

I fixed this by declaring the variable in the method signature so that the error referenced by tx.Done() will always be whatever error is returned with return.

Test plan

Added a test to make sure that a failed create actually rolls back the transaction.

Merge request reports

Approval is optional

Merged by avatar (Oct 8, 2025 10:55pm UTC)

Merge details

  • Changes merged into main with 6092ff82.
  • Deleted the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading