Skip to content

fix: roll back subscriber transaction on nack - #62

Open
Yuki9814 wants to merge 1 commit into
ThreeDotsLabs:masterfrom
Yuki9814:fix/rollback-nacked-message
Open

fix: roll back subscriber transaction on nack#62
Yuki9814 wants to merge 1 commit into
ThreeDotsLabs:masterfrom
Yuki9814:fix/rollback-nacked-message

Conversation

@Yuki9814

Copy link
Copy Markdown

Motivation / Background

When a SQL subscriber receives a Nack, it currently keeps resending inside the same query transaction. That leaves the selected row locked to one consumer and prevents another subscriber in the same consumer group from picking it up.

Addresses ThreeDotsLabs/watermill#224.

Details

  • Return a private Nack signal from message delivery so the existing query error path rolls back the transaction.
  • Preserve ResendInterval as the delay before the current subscriber queries again, giving peers a chance to acquire the message.
  • Add a focused transaction regression test that asserts Nack rolls back rather than commits.

Alternative approaches considered (if applicable)

I considered rolling back directly inside sendMessage, but keeping transaction lifecycle in query avoids coupling message delivery to the transaction implementation and reuses the existing rollback handling.

Checklist

  • I wrote tests for the changes.
  • The focused regression test passed 50 consecutive runs.
  • The focused race test passed 50 consecutive runs.
  • All packages compile and go vet ./... passes.
  • The database-backed suite could not run locally because this machine has no container runtime; repository CI remains the integration gate.
  • Code has no breaking changes.
  • Documentation changes are not applicable.

Release the query transaction when a consumer nacks a message so another subscriber in the same consumer group can pick it up. Preserve ResendInterval as the delay before the current subscriber retries.

Co-authored-by: OpenAI Codex <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant