Skip to content
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

For broken pipe, determine whether it can be encapsulated in the gin framework? #17

Open
daheige opened this issue Jun 19, 2021 · 0 comments

Comments

@daheige
Copy link

daheige commented Jun 19, 2021

zap/zap.go

Line 72 in 062a8ac

if ne, ok := err.(*net.OpError); ok {

I have also seen such code snippets in the gin framework. Here you have done this again. Is it possible to encapsulate an IsBroken func instead of writing this every time.

Just like below:

// IsBroken check for a broken connection, as it is not really a
// condition that warrants a panic stack trace.
func IsBroken(err interface{}) bool {
	if ne, ok := err.(*net.OpError); ok {
		if se, ok := ne.Err.(*os.SyscallError); ok {
			errMsg := strings.ToLower(se.Error())
			debugPrintf("os syscall error:%s", errMsg)

			if strings.Contains(errMsg, "broken pipe") ||
				strings.Contains(errMsg, "reset by peer"){
				return true
			}
		}
	}

	return false
}
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

No branches or pull requests

1 participant