Skip to content

Commit

Permalink
Merge pull request #20 from grid-x/fix/fix_close_nil_channel_panic_on…
Browse files Browse the repository at this point in the history
…_stop

Fix Panic when stopping Server before even started
  • Loading branch information
tretmar committed Apr 19, 2024
2 parents a23b2e5 + 2f245ca commit 28c3102
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ocppj/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ func NewServer(wsServer ws.WsServer, dispatcher ServerDispatcher, stateHandler S
dispatcher.SetPendingRequestState(stateHandler)

// Create server and add profiles
s := Server{Endpoint: Endpoint{}, server: wsServer, RequestState: stateHandler, dispatcher: dispatcher}
s := Server{
Endpoint: Endpoint{},
server: wsServer,
RequestState: stateHandler,
dispatcher: dispatcher,
stopped: make(chan struct{})}
for _, profile := range profiles {
s.AddProfile(profile)
}
Expand Down Expand Up @@ -130,7 +135,6 @@ func (s *Server) SetDisconnectedClientHandler(handler ClientHandler) {
// An error may be returned, if the websocket server couldn't be started.
func (s *Server) Start(listenPort int, listenPath string) {
// Set internal message handler
s.stopped = make(chan struct{})
s.server.SetCheckClientHandler(s.checkClientHandler)
s.server.SetNewClientHandler(s.onClientConnected)
s.server.SetDisconnectedClientHandler(s.onClientDisconnected)
Expand Down

0 comments on commit 28c3102

Please sign in to comment.