fix(otopcua): cancel pending rediscover timer on TriggerRediscovery + test hardening (follow-up C)

This commit is contained in:
Joseph Doherty
2026-06-26 12:57:08 -04:00
parent f7358bf4fd
commit e7d5ebe956
2 changed files with 53 additions and 24 deletions
@@ -408,10 +408,19 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
PublishHealthSnapshot();
});
ReceiveAsync<RediscoverTick>(HandleRediscoverAsync);
// The host asks for a fresh discovery pass after rebinding the driver to a new equipment. Re-kick the
// bounded loop via StartDiscovery (honours RediscoverPolicy + the ITagDiscovery guard, tagged with the
// current _initGeneration). Only handled here in Connected — non-Connected states no-op it below.
Receive<TriggerRediscovery>(_ => StartDiscovery());
// The host asks for a fresh discovery pass after rebinding the driver to a new equipment. Cancel any
// pending rediscover tick FIRST — mirroring ForceReconnect/DisconnectObserved — so a stale tick left
// over from the prior loop can't fire alongside the freshly-kicked one, then re-kick the bounded loop
// via StartDiscovery (honours RediscoverPolicy + the ITagDiscovery guard, tagged with the current
// _initGeneration). Only handled here in Connected — non-Connected states no-op it below. A stale tick
// that still slips through (one already mid-async-handler) is benign: the parent dedups
// DiscoveredNodesReady and node injection is idempotent — the Cancel just avoids the avoidable double
// pass in the common case.
Receive<TriggerRediscovery>(_ =>
{
Timers.Cancel("rediscover");
StartDiscovery();
});
ReceiveAsync<WriteAttribute>(HandleWriteAsync);
ReceiveAsync<RouteAlarmAck>(HandleAcknowledgeAsync);
ReceiveAsync<Subscribe>(HandleSubscribeAsync);