Merge pull request #123 from darfux/fix_leak_when_conn_reset
server: Fix connection issues when receiving ECONNRESET
This commit is contained in:
commit
5cc9169d1f
@ -18,11 +18,13 @@ package ttrpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -527,14 +529,12 @@ func (c *serverConn) run(sctx context.Context) {
|
|||||||
// branch. Basically, it means that we are no longer receiving
|
// branch. Basically, it means that we are no longer receiving
|
||||||
// requests due to a terminal error.
|
// requests due to a terminal error.
|
||||||
recvErr = nil // connection is now "closing"
|
recvErr = nil // connection is now "closing"
|
||||||
if err == io.EOF || err == io.ErrUnexpectedEOF {
|
if err == io.EOF || err == io.ErrUnexpectedEOF || errors.Is(err, syscall.ECONNRESET) {
|
||||||
// The client went away and we should stop processing
|
// The client went away and we should stop processing
|
||||||
// requests, so that the client connection is closed
|
// requests, so that the client connection is closed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
logrus.WithError(err).Error("error receiving message")
|
||||||
logrus.WithError(err).Error("error receiving message")
|
|
||||||
}
|
|
||||||
// else, initiate shutdown
|
// else, initiate shutdown
|
||||||
case <-shutdown:
|
case <-shutdown:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user