p2p: stop mconn channel sends without timeout (#8906) (#8911)

(cherry picked from commit 60881f1d06)

Co-authored-by: Sam Kleinman <garen@tychoish.com>
This commit is contained in:
mergify[bot]
2022-06-30 09:12:36 -04:00
committed by GitHub
co-authored by Sam Kleinman
parent 52e9e8257d
commit 8dc08b3ab3
+5 -1
View File
@@ -100,7 +100,8 @@ type MConnection struct {
// used to ensure FlushStop and OnStop
// are safe to call concurrently.
stopMtx sync.Mutex
stopMtx sync.Mutex
stopSignal <-chan struct{}
cancel context.CancelFunc
@@ -207,6 +208,7 @@ func (c *MConnection) OnStart(ctx context.Context) error {
c.quitSendRoutine = make(chan struct{})
c.doneSendRoutine = make(chan struct{})
c.quitRecvRoutine = make(chan struct{})
c.stopSignal = ctx.Done()
c.setRecvLastMsgAt(time.Now())
go c.sendRoutine(ctx)
go c.recvRoutine(ctx)
@@ -681,6 +683,8 @@ func (ch *channel) sendBytes(bytes []byte) bool {
return true
case <-time.After(defaultSendTimeout):
return false
case <-ch.conn.stopSignal:
return false
}
}