Skip to content

Commit d8b7275

Browse files
committed
connect: retry when it occurs a part of errors of read and write in a tcp ephemeral
1 parent ecc217e commit d8b7275

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cmd/connect.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"os/signal"
3030
"strings"
3131
"sync"
32+
"syscall"
3233
"time"
3334

3435
"github.com/rcrowley/go-metrics"
@@ -436,6 +437,8 @@ func connectEphemeral(ctx context.Context, addrport string) error {
436437
if err != nil {
437438
return xerrors.Errorf("could not dial %q: %w", addrport, err)
438439
}
440+
defer conn.Close()
441+
439442
if err := sock.SetLinger(conn); err != nil {
440443
return err
441444
}
@@ -450,14 +453,20 @@ func connectEphemeral(ctx context.Context, addrport string) error {
450453
}
451454

452455
if _, err := conn.Write(msg); err != nil {
453-
return xerrors.Errorf("could not write %q: %w", addrport, err)
456+
err := xerrors.Errorf("could not write %q: %w", addrport, err)
457+
if errors.Is(err, syscall.EINPROGRESS) {
458+
log.Println(err)
459+
return nil
460+
}
461+
return err
454462
}
455463
if _, err := conn.Read(msg); err != nil {
456-
return xerrors.Errorf("could not read %q: %w", addrport, err)
457-
}
458-
459-
if err := conn.Close(); err != nil {
460-
return xerrors.Errorf("could not close %q: %w", addrport, err)
464+
err := xerrors.Errorf("could not read %q: %w", addrport, err)
465+
if errors.Is(err, syscall.ECONNRESET) {
466+
log.Println(err)
467+
return nil
468+
}
469+
return err
461470
}
462471

463472
return nil

0 commit comments

Comments
 (0)