Skip to content

Commit dc536f1

Browse files
committed
proxy: clientLoop; improve handling of closed pipes
- use errors.Is to make sure we unwrap errors - also handle "syscall.WSAECONNRESET" (windows), and "syscall.ECONNRESET" (other platforms). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 1401877 commit dc536f1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

proxy/proxy_unix.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !windows
2+
3+
package proxy
4+
5+
import "syscall"
6+
7+
// errConnReset is the platform-specific "connection reset by peer".
8+
const errConnReset = syscall.ECONNRESET

proxy/proxy_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package proxy
2+
3+
import (
4+
"syscall"
5+
)
6+
7+
// errConnReset is the platform-specific "connection reset by peer".
8+
//
9+
// https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2#wsaeconnreset
10+
const errConnReset = syscall.WSAECONNRESET

proxy/tcp_proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package proxy
22

33
import (
4+
"errors"
45
"io"
56
"net"
67
"syscall"
@@ -51,7 +52,7 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
5152
if err != nil {
5253
// If the socket we are writing to is shutdown with
5354
// SHUT_WR, forward it to the other end of the pipe:
54-
if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
55+
if errors.Is(err, syscall.EPIPE) || errors.Is(err, errConnReset) {
5556
_ = from.CloseRead()
5657
}
5758
}

0 commit comments

Comments
 (0)