Skip to content

Commit

Permalink
Easee: prevent DOS when signalr connect fails due to rejected token (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jul 11, 2023
1 parent 75e9855 commit 850c093
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sync"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/easee"
"github.com/evcc-io/evcc/core/loadpoint"
Expand Down Expand Up @@ -202,7 +203,18 @@ func (c *Easee) chargerSite(charger string) (easee.Site, error) {

// connect creates an HTTP connection to the signalR hub
func (c *Easee) connect(ts oauth2.TokenSource) func() (signalr.Connection, error) {
return func() (signalr.Connection, error) {
bo := backoff.NewExponentialBackOff()
bo.MaxElapsedTime = time.Minute

return func() (conn signalr.Connection, err error) {
defer func() {
if err != nil {
time.Sleep(bo.NextBackOff())
} else {
bo.Reset()
}
}()

tok, err := ts.Token()
if err != nil {
return nil, err
Expand Down

0 comments on commit 850c093

Please sign in to comment.