Skip to content

Commit b9e0b11

Browse files
committed
p2p: interrupt MsgPipe payload read/write
This is better because protocols might not actually read the payload for some errors (msg too big, etc.) which can be a pain to test with the old behaviour.
1 parent a7bced7 commit b9e0b11

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎p2p/message.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ func (p *MsgPipeRW) WriteMsg(msg Msg) error {
185185
case p.w <- msg:
186186
if msg.Size > 0 {
187187
// wait for payload read or discard
188-
<-consumed
188+
select {
189+
case <-consumed:
190+
case <-p.closing:
191+
}
189192
}
190193
return nil
191194
case <-p.closing:
@@ -207,8 +210,8 @@ func (p *MsgPipeRW) ReadMsg() (Msg, error) {
207210
}
208211

209212
// Close unblocks any pending ReadMsg and WriteMsg calls on both ends
210-
// of the pipe. They will return ErrPipeClosed. Note that Close does
211-
// not interrupt any reads from a message payload.
213+
// of the pipe. They will return ErrPipeClosed. Close also
214+
// interrupts any reads from a message payload.
212215
func (p *MsgPipeRW) Close() error {
213216
if atomic.AddInt32(p.closed, 1) != 1 {
214217
// someone else is already closing

0 commit comments

Comments
 (0)