Back in March I wrote about a SESSION_CONTEXT bug that lies to you in parallel plans, with wrong results or AV dumps, no error, no warning. At the time it had survived since January 2022, all the way through SQL Server 2019, 2022, and 2025 CU2, and I just flagged it because it was still not fixed.
SQL Server 2025 CU6 dropped on June 17th (build 17.0.4055.5, KB5093421), and...
It's Still There
CU6 ships 19 fixes on top of CU5. Plenty got cleaned up. But scroll down to Known issues in this update and there it is again, same as before:
Queries that use the built-in SESSION_CONTEXT function might return incorrect results or trigger access violation (AV) dump files when run in parallel query plans. This issue occurs because of the manner in which SESSION_CONTEXT interacts with parallel execution threads, particularly if the session is reset for reuse.
Three years, three major versions, and now six CUs deep in the SQL Server 2025 release cycle. That darned bug refuses to die. If your app calls sp_set_session_context to stash a TenantID and your queries filter on it, all it takes is the right parallel plan under the affected conditions to potentially serve up the wrong tenant's rows — no error, no warning, just incorrect results.
The 30-Second Check
Confirm where you actually are. CU6 reports build 17.0.4055.5:
SELECT
SERVERPROPERTY('ProductVersion') AS Build, -- 17.0.4055.5 = CU6
SERVERPROPERTY('ProductUpdateLevel') AS CU; -- CU6
The Workaround Still Works
Same fix as last time, because the bug is unchanged. Trace flag 11042 forces any query referencing SESSION_CONTEXT to run serially, which sidesteps the parallel-thread propagation problem entirely.
-- Global, takes effect immediately DBCC TRACEON (11042, -1); -- Or make it permanent as a startup parameter: -T11042
It is a tradeoff -- you give up parallelism on those specific queries -- so test it before you push to prod. The full why-and-how is in the March post and nothing about the mechanics has changed.
An Old Friend Two Rows Down
SESSION_CONTEXT is not the only familiar face in the CU6 known issues. The MSDASQL linked-server error 7416 I covered earlier this month is still parked on the list too -- it has been riding along since CU4. If a linked server goes quiet after you patch, the fix could be just a 'User ID' away.
Patch for the 19 fixes. Just know that one of the bugs you might be patching for is still sitting there, politely waiting, exactly where we left it in March.
More to Read
SESSION_CONTEXT: Three Years, Two Bugs, One Workaround
Cumulative Update 6 for SQL Server 2025 (KB5093421)
SESSION_CONTEXT (Transact-SQL) - Known Issues

No comments:
Post a Comment