Skip to content

Commit

Permalink
make CloseWithError required for transport conns
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Jan 31, 2025
1 parent dfa7e28 commit 4df0ee3
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 33 deletions.
12 changes: 2 additions & 10 deletions p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn,
// If we do this in the Upgrader, we will not be able to do this.
if s.gater != nil {
if allow, _ := s.gater.InterceptUpgraded(c); !allow {
var err error
if tcc, ok := tc.(network.CloseWithErrorer); ok {
err = tcc.CloseWithError(network.ConnGated)
} else {
err = tc.Close()
}
err := tc.CloseWithError(network.ConnGated)

Check failure on line 388 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.23.x)

tc.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 388 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.22.x)

tc.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 388 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.22.x)

tc.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 388 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.23.x)

tc.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 388 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.22.x)

tc.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 388 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.23.x)

tc.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)
if err != nil {
log.Warnf("failed to close connection with peer %s and addr %s; err: %s", p, addr, err)
}
Expand Down Expand Up @@ -852,10 +847,7 @@ func (c *connWithMetrics) Close() error {
func (c *connWithMetrics) CloseWithError(errCode network.ConnErrorCode) error {
c.once.Do(func() {
c.metricsTracer.ClosedConnection(c.dir, time.Since(c.opened), c.ConnState(), c.LocalMultiaddr())
if ce, ok := c.CapableConn.(network.CloseWithErrorer); ok {
c.closeErr = ce.CloseWithError(errCode)
}
c.closeErr = c.CapableConn.Close()
c.closeErr = c.CapableConn.CloseWithError(errCode)

Check failure on line 850 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.23.x)

c.CapableConn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 850 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.22.x)

c.CapableConn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 850 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.22.x)

c.CapableConn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 850 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.23.x)

c.CapableConn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 850 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.22.x)

c.CapableConn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 850 in p2p/net/swarm/swarm.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.23.x)

c.CapableConn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)
})
return c.closeErr
}
Expand Down
6 changes: 1 addition & 5 deletions p2p/net/swarm/swarm_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ func (c *Conn) doClose(errCode network.ConnErrorCode) {
c.streams.Unlock()

if errCode != 0 {
if ce, ok := c.conn.(network.CloseWithErrorer); ok {
c.err = ce.CloseWithError(errCode)
} else {
c.err = c.conn.Close()
}
c.err = c.conn.CloseWithError(errCode)

Check failure on line 84 in p2p/net/swarm/swarm_conn.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.23.x)

c.conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 84 in p2p/net/swarm/swarm_conn.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.22.x)

c.conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 84 in p2p/net/swarm/swarm_conn.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.22.x)

c.conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 84 in p2p/net/swarm/swarm_conn.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.23.x)

c.conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 84 in p2p/net/swarm/swarm_conn.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.22.x)

c.conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 84 in p2p/net/swarm/swarm_conn.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.23.x)

c.conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)
} else {
c.err = c.conn.Close()
}
Expand Down
5 changes: 1 addition & 4 deletions p2p/net/upgrader/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,5 @@ func (t *transportConn) ConnState() network.ConnectionState {

func (t *transportConn) CloseWithError(errCode network.ConnErrorCode) error {
defer t.scope.Done()
if ce, ok := t.MuxedConn.(network.CloseWithErrorer); ok {
return ce.CloseWithError(errCode)
}
return t.Close()
return t.MuxedConn.CloseWithError(errCode)

Check failure on line 69 in p2p/net/upgrader/conn.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.23.x)

t.MuxedConn.CloseWithError undefined (type network.MuxedConn has no field or method CloseWithError)

Check failure on line 69 in p2p/net/upgrader/conn.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.22.x)

t.MuxedConn.CloseWithError undefined (type network.MuxedConn has no field or method CloseWithError)

Check failure on line 69 in p2p/net/upgrader/conn.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.22.x)

t.MuxedConn.CloseWithError undefined (type network.MuxedConn has no field or method CloseWithError)

Check failure on line 69 in p2p/net/upgrader/conn.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.23.x)

t.MuxedConn.CloseWithError undefined (type network.MuxedConn has no field or method CloseWithError)

Check failure on line 69 in p2p/net/upgrader/conn.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.22.x)

t.MuxedConn.CloseWithError undefined (type network.MuxedConn has no field or method CloseWithError)

Check failure on line 69 in p2p/net/upgrader/conn.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.23.x)

t.MuxedConn.CloseWithError undefined (type network.MuxedConn has no field or method CloseWithError)
}
6 changes: 1 addition & 5 deletions p2p/net/upgrader/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,7 @@ func (l *listener) handleIncoming() {
// if we stop accepting connections for some reason,
// we'll eventually close all the open ones
// instead of hanging onto them.
if cc, ok := conn.(network.CloseWithErrorer); ok {
cc.CloseWithError(network.ConnRateLimited)
} else {
conn.Close()
}
conn.CloseWithError(network.ConnRateLimited)

Check failure on line 165 in p2p/net/upgrader/listener.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.23.x)

conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 165 in p2p/net/upgrader/listener.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.22.x)

conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 165 in p2p/net/upgrader/listener.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.22.x)

conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 165 in p2p/net/upgrader/listener.go

View workflow job for this annotation

GitHub Actions / go-test / ubuntu (go 1.23.x)

conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 165 in p2p/net/upgrader/listener.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.22.x)

conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)

Check failure on line 165 in p2p/net/upgrader/listener.go

View workflow job for this annotation

GitHub Actions / go-test / windows (go 1.23.x)

conn.CloseWithError undefined (type transport.CapableConn has no field or method CloseWithError)
}
}()
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/quic/virtuallistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *acceptLoopRunner) innerAccept(l *listener, expectedVersion quic.Version
select {
case ch <- acceptVal{conn: conn}:
default:
conn.(network.CloseWithErrorer).CloseWithError(network.ConnRateLimited)
conn.CloseWithError(network.ConnRateLimited)
// accept queue filled up, drop the connection
log.Warn("Accept queue filled. Dropping connection.")
}
Expand Down
8 changes: 0 additions & 8 deletions p2p/transport/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,3 @@ func (c *capableConn) ConnState() network.ConnectionState {
cs.Transport = "websocket"
return cs
}

// CloseWithError implements network.CloseWithErrorer
func (c *capableConn) CloseWithError(errCode network.ConnErrorCode) error {
if ce, ok := c.CapableConn.(network.CloseWithErrorer); ok {
return ce.CloseWithError(errCode)
}
return c.Close()
}

0 comments on commit 4df0ee3

Please sign in to comment.