Skip to content

Commit 68f87b0

Browse files
authored
fix(evse): fix cable check race condition causing permanent charger inoperability (EVerest#1392) (EVerest#1900)
When the cable check thread completes after the car has already been unplugged, clear_errors_on_unplug() has already run. The late raise_cable_check_fault() then leaves the charger permanently inoperative. This fix skips raising the fault when the session has already ended (Idle/Finished state). Signed-off-by: Rishabh Vaish <rishabhvaish.904@gmail.com>
1 parent c444c7d commit 68f87b0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

modules/EVSE/EvseManager/EvseManager.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,13 +2539,18 @@ void EvseManager::fail_cable_check(const std::string& reason) {
25392539
}
25402540
r_hlc[0]->call_cable_check_finished(false);
25412541
}
2542-
2543-
// Raising a cable check fault should not happen if a cancel_transaction (DeAuthorized) is triggered
2544-
// during cable check
2542+
// Raising a cable check fault should not happen if:
2543+
// - a cancel_transaction (DeAuthorized) is triggered during cable check
2544+
// - the car has already been unplugged (Idle/Finished), which prevents a race condition
2545+
// where the detached cable check thread raises an error after clear_errors_on_unplug()
2546+
// has already run, leaving the charger permanently inoperative (see GitHub issue #1392)
2547+
const auto current_state = charger->get_current_state();
25452548
const auto last_stop_transaction_reason = charger->get_last_stop_transaction_reason();
2546-
if (not last_stop_transaction_reason.has_value() or
2547-
(last_stop_transaction_reason.has_value() and
2548-
last_stop_transaction_reason.value() != types::evse_manager::StopTransactionReason::DeAuthorized)) {
2549+
if (current_state == Charger::EvseState::Idle || current_state == Charger::EvseState::Finished) {
2550+
EVLOG_info << "Cable check failed due to: " << reason
2551+
<< ", but session already ended (car unplugged). Not raising cable check fault error.";
2552+
} else if (not last_stop_transaction_reason.has_value() or
2553+
last_stop_transaction_reason.value() != types::evse_manager::StopTransactionReason::DeAuthorized) {
25492554
// Raising the cable check error also causes the HLC stack to get notified
25502555
this->error_handling->raise_cable_check_fault(reason);
25512556
}

0 commit comments

Comments
 (0)