-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Race Condition in EVCS Component Initialization and OCPP Server Startup #2912
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ Additional details and impacted files@@ Coverage Diff @@
## develop #2912 +/- ##
==========================================
Coverage 56.63% 56.63%
Complexity 9504 9504
==========================================
Files 2251 2251
Lines 96038 96038
Branches 7090 7090
==========================================
Hits 54378 54378
Misses 39659 39659
Partials 2001 2001 |
|
||
if (presentEvcss == null) { | ||
// EVCS not yet configured, store session and retry later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that there's a possibility of sending CALL messages simultaneously from the following three locations, making it difficult to meet the requirements of Section 4.1.1 (Synchronicity) in the specification. Therefore, I think it might be an option not to boot MyJsonServer until everything is properly set up. What do you think? @Sn0w3y
openems/io.openems.edge.evcs.ocpp.server/src/io/openems/edge/evcs/ocpp/server/MyJsonServer.java
Line 104 in 3dc2d60
MyJsonServer.this.sendInitialRequests(sessionIndex, evcs); - https://github.com/OpenEMS/openems/pull/2912/files#diff-a9d06149a614c84998d6bcad6d51f36ca40834f2e200120f2a2e9bfb290601eaR285
openems/io.openems.edge.evcs.ocpp.server/src/io/openems/edge/evcs/ocpp/server/EvcsOcppServer.java
Line 99 in 3dc2d60
this.myJsonServer.sendInitialRequests(sessionId, ocppEvcs);
4.1.1. Synchronicity
A Charge Point or Central System SHOULD NOT send a CALL message to the other party unless all the CALL messages it sent before have been responded to or have timed out. A CALL message has been responded to when a CALLERROR or CALLRESULT message has been received with the message ID of the CALL message.
A CALL message has timed out when:
• it has not been responded to, and
• an implementation-dependent timeout interval has elapsed since the message was sent.Implementations are free to choose this timeout interval. It is RECOMMENDED that they take into account the kind of network used to communicate with the other party. Mobile networks typically have much longer worst-case round-trip times than fixed lines.
Description
This pull request addresses a race condition in the OpenEMS Edge project, where charging stations may attempt to connect to the OCPP server before the corresponding EVCS components are fully initialized. The solution implements an exponential backoff retry mechanism with optional randomness to handle these cases gracefully.
Problem
When the OCPP server starts, it begins accepting connections from charging stations immediately. However, the EVCS components may not be fully initialized at that time. If a charging station connects before its corresponding EVCS component is ready, the server fails to associate the session with the EVCS, leading to errors and unsuccessful connections.
Solution
MyJsonServer
class to handle new sessions when the EVCS component is not yet initialized.Changes Made
1. Modified
newSession
MethodIn
MyJsonServer.java
, thenewSession
method now checks if the EVCS component is initialized. If not, it stores the session in apendingSessions
map and initiates the retry mechanism.2. Implemented
retryNewSession
Method with Exponential BackoffAdded a new method
retryNewSession
that schedules retries using a ScheduledExecutorService. The delay between retries increases exponentially, capped at a maximum value.3. Added Necessary Data Structures
Introduced maps to keep track of retry attempts and total retry time per
ocppIdentifier
.4. Moved pendingSessions to EvcsOcppServer Class
To maintain consistency with other session management fields, moved
pendingSessions
to theEvcsOcppServer
class.5. Properly Shutdown Scheduled Executor Service
Ensured that the
ScheduledExecutorService
is properly shut down when the server is deactivated to prevent resource leaks.Related Issues
Issue #2909: Race Condition in Component Initialization and OCPP Server Startup