Skip to content

use if net.OpError.Err == syscall.EIPE, but net.OpError.Err never eq to syscall.EPIPE #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xiaotushaoxia opened this issue Dec 20, 2023 · 1 comment · May be fixed by #126
Open

use if net.OpError.Err == syscall.EIPE, but net.OpError.Err never eq to syscall.EPIPE #110

xiaotushaoxia opened this issue Dec 20, 2023 · 1 comment · May be fixed by #126

Comments

@xiaotushaoxia
Copy link

xiaotushaoxia commented Dec 20, 2023

	broker := func(to, from *net.TCPConn) {
		written, err := io.Copy(to, from)
		if err != nil {
			// If the socket we are writing to is shutdown with
			// SHUT_WR, forward it to the other end of the pipe:
			if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
				_ = from.CloseRead()
			}
		}
		_ = to.CloseWrite()
		event <- written
	}

net.OpError.Err is *os.SyscallError, os.SyscallError.Err can not be syscall.Errno

maybe this is expected behavior

	broker := func(to, from *net.TCPConn) {
		written, err := io.Copy(to, from)
		if err != nil {
			// If the socket we are writing to is shutdown with
			// SHUT_WR, forward it to the other end of the pipe:
			var errno syscall.Errno
			if errors.As(err, &errno) && errno == syscall.EPIPE {
				_ = from.CloseRead()
			}
		}
		_ = to.CloseWrite()
		event <- written
	}
@xiaotushaoxia xiaotushaoxia changed the title use if net.OpError.Err == syscall.EIPE, but net.OpError.Err never eq to syscall.EIPE use if net.OpError.Err == syscall.EIPE, but net.OpError.Err never eq to syscall.EPIPE Dec 20, 2023
@thaJeztah
Copy link
Member

Thanks for reporting; I was actually just looking at that code, and also considering to use errors.As; perhaps even just errors.Is(err, sys call.EPIPE) would do the trick, because net.OpError (and other errors) would be unwrapped by errors.Is 🤔

Let me open a draft PR for discussions; I'm also wondering if there's other errors that should be handled to detect things being closed.

@thaJeztah thaJeztah linked a pull request Apr 24, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants