@@ -584,13 +584,40 @@ func (d *DefaultServerDispatcher) messagePump() {
584584 log .Error ("dispatcher timeout for client %s triggered, but no pending request found" , clientID )
585585 continue
586586 }
587- bundle , _ := el .(RequestBundle )
588- d .CompleteRequest (clientID , bundle .Call .UniqueId )
589- log .Infof ("request %v for %v timed out" , bundle .Call .UniqueId , clientID )
590- if d .onRequestCancel != nil {
591- d .onRequestCancel (clientID , bundle .Call .UniqueId , bundle .Call .Payload ,
592- ocpp .NewError (GenericError , "Request timed out" , bundle .Call .UniqueId ))
587+
588+ switch el .(type ) {
589+ case RequestBundle :
590+ bundle , _ := el .(RequestBundle )
591+
592+ if bundle .Call == nil {
593+ log .Errorf ("invalid request bundle for client %s: Call field is nil" , clientID )
594+ continue
595+ }
596+
597+ d .CompleteRequest (clientID , bundle .Call .UniqueId )
598+
599+ log .Infof ("request %v for %v timed out" , bundle .Call .UniqueId , clientID )
600+ if d .onRequestCancel != nil {
601+ d .onRequestCancel (clientID , bundle .Call .UniqueId , bundle .Call .Payload ,
602+ ocpp .NewError (GenericError , "Request timed out" , bundle .Call .UniqueId ))
603+ }
604+
605+ case EventBundle :
606+ bundle , _ := el .(EventBundle )
607+ if bundle .Send == nil {
608+ log .Errorf ("invalid event bundle for client %s: Send field is nil" , clientID )
609+ continue
610+ }
611+
612+ d .CompleteRequest (clientID , bundle .Send .GetUniqueId ())
613+
614+ log .Infof ("request %v for %v timed out" , bundle .Send .GetUniqueId (), clientID )
615+ if d .onRequestCancel != nil {
616+ d .onRequestCancel (clientID , bundle .Send .GetUniqueId (), bundle .Send .Payload ,
617+ ocpp .NewError (GenericError , "Request timed out" , bundle .Send .GetUniqueId ()))
618+ }
593619 }
620+
594621 }
595622 case clientID = <- d .readyForDispatch :
596623 // Cancel previous timeout (if any)
0 commit comments