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

task内 panic时 会恐慌,报错:使用了关闭的channel #6

Open
1340691923 opened this issue May 10, 2021 · 0 comments
Open

Comments

@1340691923
Copy link

复现代码:

task := &timing2.Task{
Uuid: "uuid",
Job: timing2.GetJob(func() {
panic("err")
}),
RunTime: time.Now().Unix() + 90,
}

异常代码处:
job.go func (j *taskJob) run()

原因是 defer的顺序是 先进后出,原代码会先触发 j.done <- true 然后进行了 finish的逻辑,代码应改为:

defer func() {
	if !isPanic {
		j.done <- true
	}
}()

defer func() {
	if x := recover(); x != nil {
		err := errors.Errorf("job error with panic:%v", x)
		j.err <- err
		isPanic = true
		return
	}
}()
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