lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
262 stars 125 forks source link

Run websocket newClientHandler before starting pump goroutines #86

Closed michaelbeaumont closed 3 years ago

michaelbeaumont commented 3 years ago

I think the expected behavior is to have newClientHandler finish running before requests and responses start coming, which isn't a given without this PR.

lorenzodonini commented 3 years ago

Imho not a problem in real-world scenarios, since the time it takes the sender to send a request will exceed the time it takes for the callback to be invoked, by far. But fair enough.

Just fyi: I rather see a possible issue in case a custom dispatcher is being used -> invoking the callback and sending a request without buffering it in between (basically going straight to ws.Write) will cause a deadlock, since there is no goroutine to actually read that data yet. Would have to make the channel buffered to cover this edge case.