Skip to content

Commit f202713

Browse files
committed
fix: TestStatelessReset/reuseport_off test
close listener underlying connection when reuseport is disabled and the close method called Signed-off-by: gfanton <[email protected]>
1 parent 6f87195 commit f202713

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

p2p/transport/quic/conn.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type pConn interface {
1919
// count conn reference
2020
DecreaseCount()
2121
IncreaseCount()
22+
23+
// is reuseport enable
24+
Reuseport() bool
2225
}
2326

2427
type conn struct {

p2p/transport/quic/listener.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ func (l *listener) setupConn(qconn quic.Connection) (*conn, error) {
146146
// Close closes the listener.
147147
func (l *listener) Close() error {
148148
defer l.conn.DecreaseCount()
149-
return l.quicListener.Close()
149+
150+
err := l.quicListener.Close()
151+
152+
if !l.conn.Reuseport() {
153+
// close the underlying connection
154+
l.conn.Close()
155+
}
156+
return err
150157
}
151158

152159
// Addr returns the address of this listener.

p2p/transport/quic/reuse.go

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func (c *reuseConn) DecreaseCount() {
4343
c.mutex.Unlock()
4444
}
4545

46+
func (c *reuseConn) Reuseport() bool {
47+
return true
48+
}
49+
4650
func (c *reuseConn) ShouldGarbageCollect(now time.Time) bool {
4751
c.mutex.Lock()
4852
defer c.mutex.Unlock()

p2p/transport/quic/transport.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ type noreuseConn struct {
5858
*net.UDPConn
5959
}
6060

61-
func (c *noreuseConn) IncreaseCount() {}
62-
func (c *noreuseConn) DecreaseCount() {}
61+
func (c *noreuseConn) IncreaseCount() {}
62+
func (c *noreuseConn) DecreaseCount() {}
63+
func (c *noreuseConn) Reuseport() bool { return false }
6364

6465
type connManager struct {
6566
reuseUDP4 *reuse
@@ -406,6 +407,7 @@ func (t *transport) Listen(addr ma.Multiaddr) (tpt.Listener, error) {
406407
}
407408
ln, err := newListener(conn, t, t.localPeer, t.privKey, t.identity, t.rcmgr)
408409
if err != nil {
410+
conn.Close()
409411
conn.DecreaseCount()
410412
return nil, err
411413
}

0 commit comments

Comments
 (0)