Skip to content

Commit 8977f59

Browse files
darfuxdmcgowan
authored andcommitted
server: Fix connection leak when receiving ECONNRESET
The ttrpc server somtimes receives `ECONNRESET` rather than `EOF` when the client is exited. Such as reading from a closed connection. Handle it properly to avoid goroutine and connection leak. Change-Id: If32711cfc1347dd2da27ca846dd13c3f5af351bb Signed-off-by: liyuxuan.darfux <[email protected]> (cherry picked from commit a03aa04) Signed-off-by: Derek McGowan <[email protected]>
1 parent 0247db1 commit 8977f59

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net"
2525
"sync"
2626
"sync/atomic"
27+
"syscall"
2728
"time"
2829

2930
"github.com/sirupsen/logrus"
@@ -467,14 +468,12 @@ func (c *serverConn) run(sctx context.Context) {
467468
// branch. Basically, it means that we are no longer receiving
468469
// requests due to a terminal error.
469470
recvErr = nil // connection is now "closing"
470-
if err == io.EOF || err == io.ErrUnexpectedEOF {
471+
if err == io.EOF || err == io.ErrUnexpectedEOF || errors.Is(err, syscall.ECONNRESET) {
471472
// The client went away and we should stop processing
472473
// requests, so that the client connection is closed
473474
return
474475
}
475-
if err != nil {
476-
logrus.WithError(err).Error("error receiving message")
477-
}
476+
logrus.WithError(err).Error("error receiving message")
478477
case <-shutdown:
479478
return
480479
}

0 commit comments

Comments
 (0)