Skip to content

Commit 52f7e0b

Browse files
committed
Handle EOF errors as connection losses where reconnect is desired
1 parent 1fd4b31 commit 52f7e0b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/device-agent/states/connected/connected.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
78
"math"
89
"net"
910
"sync"
1011
"time"
1112

1213
"github.com/sirupsen/logrus"
1314

15+
"google.golang.org/grpc/codes"
16+
grpcstatus "google.golang.org/grpc/status"
17+
"google.golang.org/protobuf/types/known/timestamppb"
18+
1419
"github.com/nais/device/internal/device-agent/config"
1520
"github.com/nais/device/internal/device-agent/runtimeconfig"
1621
"github.com/nais/device/internal/device-agent/statemachine"
1722
"github.com/nais/device/internal/notify"
1823
"github.com/nais/device/internal/pb"
1924
"github.com/nais/device/internal/version"
20-
"google.golang.org/grpc/codes"
21-
grpcstatus "google.golang.org/grpc/status"
22-
"google.golang.org/protobuf/types/known/timestamppb"
2325
)
2426

2527
const (
@@ -103,8 +105,11 @@ func (c *Connected) Enter(ctx context.Context) statemachine.Event {
103105
c.notifier.Errorf("Unauthenticated: %v", err)
104106
c.rc.SetToken(nil)
105107
return statemachine.EventDisconnect
108+
case errors.Is(e, io.EOF):
109+
c.logger.Infof("Connection unexpectedly lost (EOF), reconnecting...")
110+
attempt = 0
106111
case errors.Is(e, ErrLostConnection):
107-
c.logger.Infof("Lost connection, reconnecting..")
112+
c.logger.Infof("Lost connection, reconnecting...")
108113
attempt = 0
109114
case errors.Is(e, context.DeadlineExceeded):
110115
c.logger.Infof("syncConfigLoop deadline exceeded: %v", err)

0 commit comments

Comments
 (0)