Skip to content

Commit 01ba839

Browse files
bhugotBenjamin HUGOT
andauthored
Added missing Rollback transaction (#219)
Co-authored-by: Benjamin HUGOT <[email protected]>
1 parent a9a1a71 commit 01ba839

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

1011
## v1.2.3
1112

src/DurableTask.SqlServer/Scripts/logic.sql

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ BEGIN
420420

421421
-- The instance ID is not auto-start and doesn't already exist, so we fail.
422422
IF @@ROWCOUNT = 0
423-
THROW 50000, 'The instance does not exist.', 1;
423+
BEGIN
424+
ROLLBACK TRANSACTION;
425+
THROW 50000, 'The instance does not exist.', 1;
426+
END
424427
END
425428

426429
-- Payloads are stored separately from the events
@@ -473,8 +476,10 @@ BEGIN
473476
)
474477

475478
IF @existingStatus IS NULL
479+
BEGIN
480+
ROLLBACK TRANSACTION;
476481
THROW 50000, 'The instance does not exist.', 1;
477-
482+
END
478483
-- If the instance is already completed, no need to terminate it.
479484
IF @existingStatus IN ('Pending', 'Running')
480485
BEGIN
@@ -835,8 +840,10 @@ BEGIN
835840
WHERE [TaskHub] = @TaskHub and [InstanceID] = @InstanceID
836841

837842
IF @@ROWCOUNT = 0
843+
BEGIN
844+
ROLLBACK TRANSACTION;
838845
THROW 50000, 'The instance does not exist.', 1;
839-
846+
END
840847
-- External event messages can create new instances
841848
-- NOTE: There is a chance this could result in deadlocks if two
842849
-- instances are sending events to each other at the same time
@@ -1079,7 +1086,10 @@ BEGIN
10791086
-- Ignore PK violations here, which can happen when multiple clients
10801087
-- try to add messages at the same time for the same instance
10811088
IF ERROR_NUMBER() <> 2627 -- 2627 is PK violation
1082-
THROW
1089+
BEGIN
1090+
ROLLBACK TRANSACTION;
1091+
THROW;
1092+
END
10831093
END CATCH
10841094

10851095
-- Insert new event data payloads into the Payloads table in batches.
@@ -1368,8 +1378,10 @@ BEGIN
13681378
-- This can happen if the message was completed by another worker, in which
13691379
-- case we don't want any of the side-effects to persist.
13701380
IF @@ROWCOUNT <> (SELECT COUNT(*) FROM @CompletedTasks)
1381+
BEGIN
1382+
ROLLBACK TRANSACTION;
13711383
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;
1372-
1384+
END
13731385
COMMIT TRANSACTION
13741386
END
13751387
GO

0 commit comments

Comments
 (0)