From a87cb59168361385ced754fdcc2b6862eb9ac632 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 10 Dec 2024 15:44:05 +0100 Subject: [PATCH] p2p: remove nil check in rlpxTransport.close --- p2p/transport.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/p2p/transport.go b/p2p/transport.go index 15d78a7d87..91e66cfe11 100644 --- a/p2p/transport.go +++ b/p2p/transport.go @@ -113,19 +113,17 @@ func (t *rlpxTransport) close(err error) { // Tell the remote end why we're disconnecting if possible. // We only bother doing this if the underlying connection supports // setting a timeout tough. - if t.conn != nil { - if reason, ok := err.(DiscReason); ok && reason != DiscNetworkError { - // We do not use the WriteMsg func since we want a custom deadline - deadline := time.Now().Add(discWriteTimeout) - if err := t.conn.SetWriteDeadline(deadline); err == nil { - // Connection supports write deadline. - t.wbuf.Reset() - rlp.Encode(&t.wbuf, []any{reason}) - t.conn.Write(discMsg, t.wbuf.Bytes()) - } + if reason, ok := err.(DiscReason); ok && reason != DiscNetworkError { + // We do not use the WriteMsg func since we want a custom deadline + deadline := time.Now().Add(discWriteTimeout) + if err := t.conn.SetWriteDeadline(deadline); err == nil { + // Connection supports write deadline. + t.wbuf.Reset() + rlp.Encode(&t.wbuf, []any{reason}) + t.conn.Write(discMsg, t.wbuf.Bytes()) } - t.conn.Close() } + t.conn.Close() } func (t *rlpxTransport) doEncHandshake(prv *ecdsa.PrivateKey) (*ecdsa.PublicKey, error) {