lorenzodonini / ocpp-go

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

Abort sending request on dropped connection? #153

Open sbindzau opened 1 year ago

sbindzau commented 1 year ago

Is there a way to abort sending a request when the connection is dropped? I found that I can set a DisconnectedHandler to realize that the connection is dropped, but is there a way to cancel the outstanding request?

I know that I can use SetTimeout() on the dispatcher to abort the request and get an error, but it would be cleaner if the dropped connection could trigger that instead of a fixed timeout. Is there a way to do that?

lorenzodonini commented 1 year ago

but is there a way to cancel the outstanding request?

Not right now. I am planning to support passing a context for every request, which will allow you to cancel it at anytime. This is not yet the case though.

I know that I can use SetTimeout() on the dispatcher to abort the request and get an error, but it would be cleaner if the dropped connection could trigger that instead of a fixed timeout. Is there a way to do that?

The dropped connection doesn't trigger a timeout because the websocket will attempt to reconnect. All the queued requests that weren't transmitted already will be retransmitted, so that's why no callback is being called. It's meant to provide you a seamless experience without you having to bother about retrying manually.

lorenzodonini commented 1 year ago

FYI my explanation holds only for client implementations. Servers drop the state as soon as a client is disconnected, invoking the respective error callbacks.

sbindzau commented 1 year ago

If the client is offline for a longer time (hours, days even months) old StatusNotifications can pile up and are not really interesting for the server once connection is established, that's why I want to be able to throw away (some) messages. The timeout will do for now, though