fix(opcua): trigger reconnect on BadTimeout and tighten subscription params

Remove the special-case that silently ignored BadTimeout in the
subscription status callback. BadTimeout means the server has already
dropped the subscription, so reconnect must be triggered immediately
rather than waiting for the heartbeat check.

Also reduce lifetime_count (120→15) and max_keep_alive_count (10→5)
so failures are detected within 15s instead of 120s, while still
satisfying the OPC UA spec requirement of lifetime >= 3×keepalive.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
caoqianming 2026-03-24 12:50:55 +08:00
parent 0b9b7aef7d
commit 2d80266422
1 changed files with 2 additions and 9 deletions

View File

@ -1153,21 +1153,14 @@ impl ConnectionManager {
match session match session
.create_subscription( .create_subscription(
Duration::from_secs(1), Duration::from_secs(1),
120, 15,
10, 5,
0, 0,
0, 0,
true, true,
opcua::client::SubscriptionCallbacks::new( opcua::client::SubscriptionCallbacks::new(
move |notification| { move |notification| {
if notification.status.is_bad() { if notification.status.is_bad() {
if notification.status == opcua::types::StatusCode::BadTimeout {
tracing::warn!(
"Subscription publish timeout for source {}, waiting for heartbeat validation before reconnect",
current_source_id
);
return;
}
tracing::warn!( tracing::warn!(
"Subscription status changed to {:?} for source {}, triggering reconnection", "Subscription status changed to {:?} for source {}, triggering reconnection",
notification.status, notification.status,