File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2193,6 +2193,15 @@ WITH
21932193 JOIN #blocking AS bg
21942194 ON bg .monitor_loop = h .monitor_loop
21952195 AND bg .blocking_desc = h .blocked_desc
2196+ /*
2197+ Cycle guard: skip a row whose blocked_desc already appears in the
2198+ accumulated sort_order. Two sessions can briefly appear to block each
2199+ other in the same monitor_loop (before the deadlock monitor fires),
2200+ and without a guard the recursion has no exit. The sort_order string
2201+ contains every (SPID:ECID) we've visited on this branch; checking for
2202+ the candidate blocked_desc before we follow it prevents the cycle.
2203+ */
2204+ WHERE h .sort_order NOT LIKE ' %' + bg .blocked_desc + ' %'
21962205)
21972206UPDATE
21982207 #blocked
@@ -2204,7 +2213,13 @@ JOIN hierarchy AS h
22042213 ON h .monitor_loop = b .monitor_loop
22052214 AND h .blocking_desc = b .blocking_desc
22062215 AND h .blocked_desc = b .blocked_desc
2207- OPTION (RECOMPILE , MAXRECURSION 0 );
2216+ /*
2217+ MAXRECURSION 100 (the default) is plenty for real blocking chains and
2218+ still acts as a backstop if the cycle guard above is ever bypassed by
2219+ a blocked_desc that doesn't format the same way as expected. Reverted
2220+ from MAXRECURSION 0 which gave the runaway case no ceiling at all.
2221+ */
2222+ OPTION (RECOMPILE , MAXRECURSION 100 );
22082223
22092224IF @debug = 1
22102225BEGIN
You can’t perform that action at this time.
0 commit comments