]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
fix(charging-station): re-dial after a server-initiated connection close (#2021)
authorDaniel <7558512+DerGenaue@users.noreply.github.com>
Fri, 17 Jul 2026 15:22:18 +0000 (17:22 +0200)
committerGitHub <noreply@github.com>
Fri, 17 Jul 2026 15:22:18 +0000 (17:22 +0200)
commit6f7bcb64be5467894e595dbdc9d3ad4703fb1541
tree00e20b9132370aab3c6872f4c7e7ce9c9aa64461
parent27093f1b26b36e7fcae30b4410a3191a8e9c17f1
fix(charging-station): re-dial after a server-initiated connection close (#2021)

* fix(charging-station): re-dial after a server-initiated connection close

When the CSMS or a proxy closed a station's WebSocket with a normal
(clean) close, the station stayed "started but not connected" instead of
reconnecting. onClose only re-dialed on abnormal close codes and treated
clean closes as terminal, but a clean close cannot be told apart by code
from the station's own closeWSConnection() (the UI disconnect action,
which must stay down). Real charge-point hardware re-dials after losing
the connection regardless of the close code.

Mark only explicitly-requested closes (the UI disconnect) as terminal via
a byRequest flag on closeWSConnection(), and reconnect on any close the
station did not request while it is still started -- clean or abnormal.
This also fixes certificate rotation, which closes the socket to force a
re-dial with the new certificate and previously never reconnected.

Closes #2016.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
* refactor(charging-station): pass closeWSConnection intent via an options object

Match the paired openWSConnection signature and make the call site
self-documenting: closeWSConnection({ byRequest: true }) rather than a bare
positional boolean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
* test(charging-station): cover the onClose reconnect decision

Drive onClose directly with a spied reconnect: the station re-dials after a
server-initiated normal close while started, and stays disconnected after an
operator-requested close. Removes a stale test that only asserted the socket
reached CLOSED, which held regardless of the reconnect decision.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
* docs(charging-station): harmonize reconnect terminology and tighten close comments

- Use the codebase's "reconnect" term consistently (drop "re-dial"), and
  "server-initiated"/"requested" to match the PR title and the byRequest option.
- Tighten the closeWSConnection JSDoc and onClose comments; align the JSDoc
  @param style (no trailing period) with the sibling openWSConnection.
- Prefix the reconnect test titles with "should" per tests/TEST_STYLE_GUIDE.md.

No behavior change.

---------

Signed-off-by: Daniel <7558512+DerGenaue@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts
tests/charging-station/ChargingStation-Reconnect.test.ts [new file with mode: 0644]
tests/charging-station/ChargingStation-Resilience.test.ts
tests/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.test.ts