diff --git a/src/features/device-logs/lib/read.ts b/src/features/device-logs/lib/read.ts index 728843dc8f..b0271d0377 100644 --- a/src/features/device-logs/lib/read.ts +++ b/src/features/device-logs/lib/read.ts @@ -115,26 +115,30 @@ async function handleStreamingRead( } }); - let heartbeatTimeout: ReturnType | null = null; + let heartbeatInterval: ReturnType | null = null; function heartbeat() { if (state !== StreamState.Closed) { // In order to keep the connection alive, output new lines every now and then write('\n'); - heartbeatTimeout = setTimeout(heartbeat, LOGS_HEARTBEAT_INTERVAL); + return; + } + if (heartbeatInterval != null) { + clearInterval(heartbeatInterval); + heartbeatInterval = null; } } - heartbeatTimeout = setTimeout(heartbeat, LOGS_HEARTBEAT_INTERVAL); + heartbeatInterval = setInterval(heartbeat, LOGS_HEARTBEAT_INTERVAL); function close() { if (state !== StreamState.Closed) { state = StreamState.Closed; getBackend().unsubscribe(ctx, onLog); } - if (heartbeatTimeout != null) { - clearTimeout(heartbeatTimeout); - heartbeatTimeout = null; + if (heartbeatInterval != null) { + clearInterval(heartbeatInterval); + heartbeatInterval = null; } }