From 2967b142fe110f6c01b520a67827f57e9eb1025e Mon Sep 17 00:00:00 2001 From: Yilun Date: Mon, 3 Aug 2020 01:38:56 -0700 Subject: [PATCH] Add conn closed error to prevent closed conn hanging forever Signed-off-by: Yilun --- connection.go | 6 ++++++ errors.go | 1 + 2 files changed, 7 insertions(+) diff --git a/connection.go b/connection.go index bcc5c1c..d0e9909 100644 --- a/connection.go +++ b/connection.go @@ -159,6 +159,9 @@ func (conn *Connection) tx() error { if conn.session.IsClosed() { return ErrSessionClosed } + if err == ErrConnClosed { + return err + } log.Println(err) select { case conn.session.resendChan <- seq: @@ -234,6 +237,9 @@ func (conn *Connection) sendAck() error { err = conn.session.sendWith(conn.localClientID, conn.remoteClientID, buf, conn.retransmissionTimeout) if err != nil { + if err == ErrConnClosed { + return err + } log.Println(err) time.Sleep(time.Second) continue diff --git a/errors.go b/errors.go index 916b48f..f2960c0 100644 --- a/errors.go +++ b/errors.go @@ -11,6 +11,7 @@ var ( ErrInvalidPacket = NewGenericError("invalid packet", false, true) ErrRecvWindowFull = NewGenericError("receive window full", false, true) ErrNotHandshake = NewGenericError("first packet is not handshake packet", false, true) + ErrConnClosed = NewGenericError("connection closed", false, false) ) type GenericError struct {