Skip to content

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

@daheige

Description

@daheige

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions