From b75542bbacea766ff5790ffd2870b927a6fe41dc Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 22 May 2026 08:15:58 -0400 Subject: [PATCH] fix(scripted-alarms): resolve Medium code-review finding (Core.ScriptedAlarms-002) Dispose any existing _shelvingTimer before reassigning it inside LoadAsync so that a second LoadAsync call does not leak the old timer and leave two timers running concurrently against the same engine state. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ScriptedAlarmEngine.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms/ScriptedAlarmEngine.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms/ScriptedAlarmEngine.cs index 6ce5e52..e42b629 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms/ScriptedAlarmEngine.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms/ScriptedAlarmEngine.cs @@ -165,6 +165,11 @@ public sealed class ScriptedAlarmEngine : IDisposable _loaded = true; _engineLogger.Information("ScriptedAlarmEngine loaded {Count} alarm(s)", _alarms.Count); + // Dispose any previously-created timer before reassigning; a second LoadAsync + // call without this would leave two timers firing against the same engine. + // (Core.ScriptedAlarms-002) + _shelvingTimer?.Dispose(); + // Start the shelving-check timer — ticks every 5s, expires any timed shelves // that have passed their UnshelveAtUtc. _shelvingTimer = new Timer(_ => RunShelvingCheck(),