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

runtime: call返回的err,类型为net.(*OpError)调用时panic #776

Closed
arch3754 opened this issue Jan 20, 2023 · 5 comments
Closed

runtime: call返回的err,类型为net.(*OpError)调用时panic #776

arch3754 opened this issue Jan 20, 2023 · 5 comments

Comments

@arch3754
Copy link
Contributor

如图:
image

部署环境是在公网,请求的目标地址也是公网
以下是对应代码块,在fmt.Sprintf("%v", err)时panic

func call(i interface{}) {
	f := i.(*ProbePlanning)
	arg := &model.ProbeArg{
		Stra:     f.stra,
		Endpoint: f.endpoint,
		Agent:    f.agent,
	}
	var err error
	defer func() {
		if e := recover(); e != nil {
			if ee, ok := e.(error); ok {
				err = ee
				return
			}

			err = fmt.Errorf("failed to get xclient: %v", e)
		}
	}()

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	defer cancel()
	var reply model.ProbeReply
	err = f.xc.Get().Call(ctx, "Probe", arg, &reply)
	if err != nil {
		f.ch <- &model.ProbeReply{
			Stra:      arg.Stra,
			Endpoint:  arg.Endpoint,
			Agent:     arg.Agent,
			Code:      0,
			RpcError:  fmt.Sprintf("%v", err),
			Timestamp: time.Now().Unix(),
		}
		return
	}
	f.ch <- &reply
}
@smallnest
Copy link
Owner

@arch3754 你的go 版本是多少?

@smallnest
Copy link
Owner

当err是(*net.OpError)时,把这个err的各字段信息打印出来,看看哪里有问题,或许踩到了一个go的bug.

type OpError struct {
	Op string
	Net string
	Source Addr
	Addr Addr
	Err error
}

@smallnest
Copy link
Owner

尤其是Err字段,可以同时%T打印出这个字段的实际类型

@smallnest
Copy link
Owner

如果你不能复现,我建议你加一层保护,如果是(*net.OpError), 直接返回*net.OpError, 而不是fmt.Sprintf("%v", err)

当然,如果你能复现是最好了。 复现的时候先把这个net.OpError各字段信息打印出来,看看有没有啥异常。

@arch3754
Copy link
Contributor Author

go 版本1.18.5和1.19.2都有问题,我先打出来试试,不太容易复现,好多天才能复现一次

smallnest added a commit that referenced this issue Jan 31, 2023
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

2 participants