Skip to content

Commit e185df8

Browse files
Merge fix/humanevents-cleanup-like-anchor into dev
2 parents fe8189f + 4ffacfa commit e185df8

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

sp_HumanEvents/sp_HumanEvents.sql

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4831,7 +4831,22 @@ BEGIN
48314831

48324832
SET @executer = QUOTENAME(@output_database_name) + N'.sys.sp_executesql ';
48334833

4834-
/*Clean up sessions*/
4834+
/*
4835+
Clean up sessions. Match only what sp_HumanEvents itself creates:
4836+
HumanEvents_<event_type>_<guid> (one-shot, @keep_alive = 0)
4837+
keeper_HumanEvents_<event_type> (@keep_alive = 1)
4838+
4839+
Previous pattern N'%HumanEvents_%' had two issues:
4840+
- unanchored leading % — a user session named "MyHumanEventsFoo"
4841+
would match and get dropped.
4842+
- unescaped _ — LIKE treats _ as a single-char wildcard, so
4843+
"HumanEventsMonitor" (no literal underscore) would match via the
4844+
trailing % + the _ wildcard eating any one character.
4845+
4846+
Anchored to the prefix and escaped the literal underscore with a
4847+
bracket class so an operator using HumanEvents-adjacent names for
4848+
their own XE sessions isn't collateral damage.
4849+
*/
48354850
IF @azure = 0
48364851
BEGIN
48374852
SELECT
@@ -4843,7 +4858,8 @@ BEGIN
48434858
FROM sys.server_event_sessions AS ses
48444859
LEFT JOIN sys.dm_xe_sessions AS dxs
48454860
ON dxs.name = ses.name
4846-
WHERE ses.name LIKE N'%HumanEvents_%';
4861+
WHERE ses.name LIKE N'HumanEvents[_]%'
4862+
OR ses.name LIKE N'keeper[_]HumanEvents[_]%';
48474863
END;
48484864
ELSE
48494865
BEGIN
@@ -4856,7 +4872,8 @@ BEGIN
48564872
FROM sys.database_event_sessions AS ses
48574873
LEFT JOIN sys.dm_xe_database_sessions AS dxs
48584874
ON dxs.name = ses.name
4859-
WHERE ses.name LIKE N'%HumanEvents_%';
4875+
WHERE ses.name LIKE N'HumanEvents[_]%'
4876+
OR ses.name LIKE N'keeper[_]HumanEvents[_]%';
48604877
END;
48614878

48624879
EXECUTE sys.sp_executesql

0 commit comments

Comments
 (0)