node-red-contrib-ocpp
node-red-contrib-ocpp copied to clipboard
cb_map handling is racy
After 2 weeks-ish of runtime with a real CB I have noticed that at some point I would no longer be able to send any messages to the CB via CB request JSON node due to {cbId} not connected. However at the same time the CS server node was producing MeterValues messages sent by that same cbId, clearly making it connected.
I did not have in-depth logging enabled, however a brief code review suggests that the following situation might have caused the observed issue:
CB request JSONnode determines the websocket to use throughcb_mapdata structure;cb_mapis inserted to, and removed from, as websocket connects or disconnects;- It is possible that the following sequence of events occurs:
- CB connects to the OCPP server with connection 1 (thus populating
cbIdin thecb_map); - Some time later CB connects to the OCPP server with connection 2 (thus replacing the
cbIdentry in thecb_mapand removing the value for connection 1) - The connection 1 is terminated, times out, etc. This causes
cb_map.remove(cbId)thus removing the entry for connection 2.
- CB connects to the OCPP server with connection 1 (thus populating
In principle I don't see any reason why multiple connections with the same cbId couldn't be made, but this library would likely behave incorrectly in such scenarios.