Skip to content

Commit

Permalink
Added missing Rollback transaction (#219)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin HUGOT <benjamin.hugot@younited-credit.fr>
  • Loading branch information
bhugot and Benjamin HUGOT committed May 7, 2024
1 parent a9a1a71 commit 01ba839
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Replace hardcoded version string + globs with build variables ([#213](https://github.com/microsoft/durabletask-mssql/pull/213))
* Fix deadlock issue on orchestration creation ([#218](https://github.com/microsoft/durabletask-mssql/pull/218)) - contributed by [@microrama](https://github.com/microrama)
* Add missing transaction rollbacks in sprocs ([#219](https://github.com/microsoft/durabletask-mssql/pull/219)) - contributed by [@bhugot](https://github.com/bhugot)

## v1.2.3

Expand Down
22 changes: 17 additions & 5 deletions src/DurableTask.SqlServer/Scripts/logic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ BEGIN

-- The instance ID is not auto-start and doesn't already exist, so we fail.
IF @@ROWCOUNT = 0
THROW 50000, 'The instance does not exist.', 1;
BEGIN
ROLLBACK TRANSACTION;
THROW 50000, 'The instance does not exist.', 1;
END
END

-- Payloads are stored separately from the events
Expand Down Expand Up @@ -473,8 +476,10 @@ BEGIN
)

IF @existingStatus IS NULL
BEGIN
ROLLBACK TRANSACTION;
THROW 50000, 'The instance does not exist.', 1;

END
-- If the instance is already completed, no need to terminate it.
IF @existingStatus IN ('Pending', 'Running')
BEGIN
Expand Down Expand Up @@ -835,8 +840,10 @@ BEGIN
WHERE [TaskHub] = @TaskHub and [InstanceID] = @InstanceID

IF @@ROWCOUNT = 0
BEGIN
ROLLBACK TRANSACTION;
THROW 50000, 'The instance does not exist.', 1;

END
-- External event messages can create new instances
-- NOTE: There is a chance this could result in deadlocks if two
-- instances are sending events to each other at the same time
Expand Down Expand Up @@ -1079,7 +1086,10 @@ BEGIN
-- Ignore PK violations here, which can happen when multiple clients
-- try to add messages at the same time for the same instance
IF ERROR_NUMBER() <> 2627 -- 2627 is PK violation
THROW
BEGIN
ROLLBACK TRANSACTION;
THROW;
END
END CATCH

-- Insert new event data payloads into the Payloads table in batches.
Expand Down Expand Up @@ -1368,8 +1378,10 @@ BEGIN
-- This can happen if the message was completed by another worker, in which
-- case we don't want any of the side-effects to persist.
IF @@ROWCOUNT <> (SELECT COUNT(*) FROM @CompletedTasks)
BEGIN
ROLLBACK TRANSACTION;
THROW 50002, N'Failed to delete the completed task events(s). They may have been deleted by another worker, in which case the current execution is likely a duplicate. Any results or pending side-effects of this task activity execution will be discarded.', 1;

END
COMMIT TRANSACTION
END
GO
Expand Down

0 comments on commit 01ba839

Please sign in to comment.