OCPP: fix flaky test deadlock between trigger handler and WS read loop (#29725)

This commit is contained in:
andig 2026-05-07 18:53:08 +02:00 • committed by GitHub
parent 948b64675d
commit 7a24dbd3f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,10 @@ type ChargePointHandler struct {
// core
func (handler *ChargePointHandler) OnChangeAvailability(request *core.ChangeAvailabilityRequest) (confirmation *core.ChangeAvailabilityConfirmation, err error) {
defer func() { handler.triggerC <- core.ChangeAvailabilityFeatureName }()
// dispatch asynchronously: the trigger handler issues synchronous CP→CS
// requests whose responses are read by this same goroutine, so a blocking
// send would deadlock the WebSocket read loop
go func() { handler.triggerC <- core.ChangeAvailabilityFeatureName }()
return core.NewChangeAvailabilityConfirmation(core.AvailabilityStatusAccepted), nil
}
@ -61,7 +64,8 @@ func (handler *ChargePointHandler) OnUnlockConnector(request *core.UnlockConnect
}
func (handler *ChargePointHandler) OnTriggerMessage(request *remotetrigger.TriggerMessageRequest) (confirmation *remotetrigger.TriggerMessageConfirmation, err error) {
defer func() { handler.triggerC <- request.RequestedMessage }()
// see OnChangeAvailability for why this is async
go func() { handler.triggerC <- request.RequestedMessage }()
return remotetrigger.NewTriggerMessageConfirmation(remotetrigger.TriggerMessageStatusAccepted), nil
}