fix(ocpp): resolve memory leak, heartbeat tracking, and timer cleanup#6
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Thanks for this, and for clearly splitting the PR into three independent fixes. Changes #2 (update Change #1 (the What the change does
Why it's a no-op in practiceThe connection counter is already self-cleaning on disconnect. The if (entry.count <= 1) ipConnectionCounts.delete(remoteIp);
else entry.count--;An entry goes This also means there is no stale-entry leak to fix. An entry exists only while that IP has a live connection and is removed when the connection closes. A station holding a long-lived socket keeps its entry at The comment actually confirms this// Only delete entries with 0 active connections — entries with count > 0
// represent live connections and must not be removed on time alone or the
// per-IP connection limit can be bypassed for long-lived connections.The reasoning is sound: you must not evict a Contrast with
|
42a01c0 to
7743ed9
Compare
…d timer - Update lastHeartbeat on CALLRESULT/CALLERROR so responsive stations aren't falsely disconnected - Clear ipMessageCleanupTimer on server shutdown to prevent orphaned interval
7743ed9 to
52ce5f5
Compare
Description
This PR fixes three issues in
packages/ocpp/src/server/ocpp-server.ts:1. Memory leak —
ipConnectionCountsstale entries never cleanedThe
ipConnectionCountsmap stores per-IP connection counts but had no periodic cleanup mechanism, unlikeipMessageCounterswhich already usesensureIpMessageCleanup().Changes:
numberto{ count, lastSeen }2. Liveness false disconnect —
lastHeartbeatnot updated onCALLRESULT/CALLERRORsession.lastHeartbeatwas only updated for incomingCALLmessages.As a result, stations that only responded to CSMS-initiated requests using
CALLRESULTorCALLERROR(without sending their ownCALLmessages) could be incorrectly considered idle and disconnected byPingMonitor.checkHeartbeats()after the heartbeat timeout.Changes:
session.lastHeartbeatfor incomingCALLRESULTandCALLERRORmessages as well3. Orphaned timer —
ipMessageCleanupTimernever cleared on shutdownThe cleanup interval created by
ensureIpMessageCleanup()was never stopped when the server shut down.Changes:
clearInterval()instop()Type of Change
Testing
tsc --noEmit)Contributor License Agreement