Skip to content

Commit 4b0e16b

Browse files
fix: quiet expected Dahua_RPC session re-auth and raise keepAlive timeout
These cameras enforce an absolute session lifetime (~30 min) that keepAlive cannot extend, so a periodic keepAlive failure followed by re-authentication is normal, not an error. Log the (re-)login at Debug instead of Info so it no longer spams the logs every ~30 min, and raise the requested keepAlive timeout from 20s to 60s so it comfortably exceeds the daemon's 30s ping interval. refs ZoneMinder#4875
1 parent 20f95cc commit 4b0e16b

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

scripts/ZoneMinder/lib/ZoneMinder/Control/Dahua_RPC.pm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ sub login {
143143
loginType => 'Direct', authorityType => 'Default', passwordType => 'Default' },
144144
login => 1);
145145
if ($r and $r->{result}) {
146-
Info('Dahua_RPC: logged in to '.$self->{host});
146+
Debug('Dahua_RPC: logged in to '.$self->{host});
147147
return 1;
148148
}
149149
Error('Dahua_RPC: login failed: '.(($r and $r->{error}) ? $r->{error}{message} : 'no/!result response'));
@@ -336,13 +336,17 @@ sub lightStatus {
336336
return { WhiteLight => ($status ? $status->{WhiteLight} : undef) };
337337
}
338338

339-
# Send a keepalive ping to prevent session expiry in long-running daemons.
340-
# Call periodically (every ~30s) from the control daemon's idle loop.
339+
# Send a keepalive ping to prevent idle session expiry in long-running daemons.
340+
# Call periodically (every ~30s) from the control daemon's idle loop. The
341+
# requested timeout must comfortably exceed the ping interval. Note: these
342+
# cameras also enforce an absolute session lifetime (~30 min) that keepAlive
343+
# cannot extend, so an occasional failure here is expected and simply triggers
344+
# a re-authentication.
341345
sub keepAlive {
342346
my $self = shift;
343-
my $r = $self->rpc_call('global.keepAlive', { timeout => 20 });
347+
my $r = $self->rpc_call('global.keepAlive', { timeout => 60 });
344348
if (!$r || !$r->{result}) {
345-
Debug('Dahua_RPC: keepAlive failed, re-logging in');
349+
Debug('Dahua_RPC: keepAlive did not confirm session, re-authenticating');
346350
$self->login();
347351
}
348352
}

0 commit comments

Comments
 (0)