Skip to content

Commit cd95699

Browse files
committed
prefer errors.Is(err, net.ErrClosed) over detecting "use of closed network connection"
Use `errors.Is(err, net.ErrClosed)` in `ClosableListeners.forwardTCP`. Since golang/go#4373 has been fixed. Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
1 parent 6c5ee21 commit cd95699

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pkg/portfwd/listener.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package portfwd
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"net"
1011
"strings"
@@ -105,7 +106,7 @@ func (p *ClosableListeners) forwardTCP(ctx context.Context, client *guestagentcl
105106
for {
106107
conn, err := tcpLis.Accept()
107108
if err != nil {
108-
if opErr, ok := err.(*net.OpError); ok && opErr.Err.Error() == "use of closed network connection" {
109+
if errors.Is(err, net.ErrClosed) {
109110
return
110111
}
111112
logrus.Errorf("failed to accept TCP connection: %v", err)

0 commit comments

Comments
 (0)