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

This commit is contained in:
Sam Kleinman
2022-06-30 09:01:02 -04:00
committed by GitHub
parent 3bec1668c6
commit 60881f1d06

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
}
}