Skip to content

Commit e6eb4c6

Browse files
committed
Consider network timeouts transcient error
1 parent 517aa36 commit e6eb4c6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/pkg/cli/tail.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"regexp"
1010
"strings"
11+
"syscall"
1112
"time"
1213

1314
"github.com/DefangLabs/defang/src/pkg"
@@ -177,12 +178,26 @@ func Tail(ctx context.Context, client client.Client, params TailOptions) error {
177178
}
178179

179180
func isTransientError(err error) bool {
181+
if errors.Is(err, io.ErrUnexpectedEOF) {
182+
return true
183+
}
184+
185+
// Consider connection reset error as transient
186+
if errors.Is(err, syscall.ECONNRESET) {
187+
return true
188+
}
189+
190+
// Network timeouts are transient, not using Temporary() because it's not always accurate
191+
// See https://pkg.go.dev/net#Error
192+
if neterr, ok := err.(interface{ Timeout() bool }); ok && neterr.Timeout() {
193+
return true
194+
}
195+
180196
// TODO: detect ALB timeout (504) or Fabric restart and reconnect automatically
181197
code := connect.CodeOf(err)
182198
// Reconnect on Error: internal: stream error: stream ID 5; INTERNAL_ERROR; received from peer
183199
return code == connect.CodeUnavailable ||
184-
(code == connect.CodeInternal && !connect.IsWireError(err)) ||
185-
errors.Is(err, io.ErrUnexpectedEOF)
200+
(code == connect.CodeInternal && !connect.IsWireError(err))
186201

187202
}
188203

0 commit comments

Comments
 (0)