Skip to content

Commit 41e1297

Browse files
committed
peer: make ping manager send sync
In this commit, we make the ping manager sync blocking. This ensures that we don't start the ping timer until after we've actually sent out the ping on the wire. Otherwise, it's possible that if processing the normal outgoing queue is very delayed, that we expire the ping timer before we even send anything out to the remote peer. We also increase the msg size buffer. As otherwise, due to TCP head of the line blocking, we can still timeout the ping sends if we're just waiting for the remote party to receive the ping in the first place after a flurry of sends.
1 parent 67a40c9 commit 41e1297

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

peer/brontide.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const (
9494
torTimeoutMultiplier = 3
9595

9696
// msgStreamSize is the size of the message streams.
97-
msgStreamSize = 5
97+
msgStreamSize = 256
9898
)
9999

100100
var (
@@ -733,7 +733,15 @@ func NewBrontide(cfg Config) *Brontide {
733733
IntervalDuration: p.scaleTimeout(pingInterval),
734734
TimeoutDuration: p.scaleTimeout(pingTimeout),
735735
SendPing: func(ping *lnwire.Ping) {
736-
p.queueMsg(ping, nil)
736+
// We'll provide an errChan so we can make this a fully
737+
// synchronous send.
738+
errChan := make(chan error, 1)
739+
p.queueMsg(ping, errChan)
740+
741+
select {
742+
case <-errChan:
743+
case <-p.cg.Done():
744+
}
737745
},
738746
OnPongFailure: func(err error) {
739747
eStr := "pong response failure for %s: %v " +

peer/ping_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ func (m *PingManager) pingHandler() {
141141
PaddingBytes: m.cfg.NewPingPayload(),
142142
}
143143

144-
// Set up our bookkeeping for the new Ping.
144+
m.cfg.SendPing(ping)
145+
146+
// Set up our bookkeeping as we've sent the ping.
145147
if err := m.setPingState(pongSize); err != nil {
146148
m.cfg.OnPongFailure(err)
147149

148150
return
149151
}
150152

151-
m.cfg.SendPing(ping)
152-
153153
case <-m.pingTimeout.C:
154154
m.resetPingState()
155155

0 commit comments

Comments
 (0)