Skip to content

Commit

Permalink
Merge pull request #3 from shsjshentao/fixbug/connleak
Browse files Browse the repository at this point in the history
fix connection leak
  • Loading branch information
shsjshentao authored Nov 27, 2020
2 parents bfba540 + b91122b commit 8edda8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ func filterCloseErr(err error) error {
switch {
case err == nil:
return nil
case err == io.EOF:
return ErrClosed
case errors.Cause(err) == io.EOF:
return ErrClosed
case errors.Cause(err) == io.ErrUnexpectedEOF:
return ErrClosed
case strings.Contains(err.Error(), "use of closed network connection"):
return ErrClosed
default:
Expand Down
14 changes: 5 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ttrpc

import (
"context"
"io"
"math/rand"
"net"
"sync"
Expand Down Expand Up @@ -457,7 +456,9 @@ func (c *serverConn) run(sctx context.Context) {
}

if err := ch.send(response.id, messageTypeResponse, p); err != nil {
logrus.WithError(err).Error("failed sending message on channel")
if filterCloseErr(err) != ErrClosed {
logrus.WithError(err).Error("failed sending message on channel")
}
return
}

Expand All @@ -466,15 +467,10 @@ func (c *serverConn) run(sctx context.Context) {
// TODO(stevvooe): Not wildly clear what we should do in this
// branch. Basically, it means that we are no longer receiving
// requests due to a terminal error.
recvErr = nil // connection is now "closing"
if err == io.EOF || err == io.ErrUnexpectedEOF {
// The client went away and we should stop processing
// requests, so that the client connection is closed
return
}
if err != nil {
if filterCloseErr(err) != ErrClosed {
logrus.WithError(err).Error("error receiving message")
}
return
case <-shutdown:
return
}
Expand Down

0 comments on commit 8edda8f

Please sign in to comment.