Skip to content

Commit

Permalink
Add conn closed error to prevent closed conn hanging forever
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Aug 3, 2020
1 parent 711a2d0 commit 2967b14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2967b14

Please sign in to comment.