From 6617c338d891160bc0110966b458e60f5387127b Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Sun, 11 May 2025 14:33:12 +0800 Subject: [PATCH] pipeline read discv5 Signed-off-by: Chen Kai <281165273grape@gmail.com> --- p2p/discover/v5_udp.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/p2p/discover/v5_udp.go b/p2p/discover/v5_udp.go index 677143fd60..beb766e697 100644 --- a/p2p/discover/v5_udp.go +++ b/p2p/discover/v5_udp.go @@ -619,9 +619,15 @@ func (t *UDPv5) dispatch() { t.send(r.destID, r.destAddr, r.msg, nil) case p := <-t.packetInCh: + // Arm next read immediately to allow pipelining. + // The readLoop can start reading the next packet while this one is being handled. + // Backpressure is still maintained by packetInCh (buffer 1) and readNextCh (buffer 1). + select { + case t.readNextCh <- struct{}{}: + case <-t.closeCtx.Done(): // Avoid blocking on send if closing + return + } t.handlePacket(p.Data, p.Addr) - // Arm next read. - t.readNextCh <- struct{}{} case <-t.closeCtx.Done(): close(t.readNextCh)