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

os/grpool: AddWithRecover Panic #3589

Closed
fainc opened this issue May 17, 2024 · 4 comments
Closed

os/grpool: AddWithRecover Panic #3589

fainc opened this issue May 17, 2024 · 4 comments
Labels

Comments

@fainc
Copy link
Contributor

fainc commented May 17, 2024

Go version

1.21.6

GoFrame version

2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

_ = grpool.AddWithRecover(ctx, func(ctx context.Context) {
gtimer.SetInterval(ctx, 5*time.Second, func(ctx context.Context) {
err = service.CrmClientProtect().ProtectHandler(gctx.NeverDone(ctx))
if err != nil {
g.Dump(err)
}
g.Dump(err.Error()) // panic it
})
}, func(ctx context.Context, err error) {
g.Dump(err)
})

What did you see happen?

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: exception recovered: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x17a4a1e]

goroutine 104 [running]:
github.com/gogf/gf/v2/os/gtimer.(*Entry).Run.func1.1()
/Users/x/go/pkg/mod/github.com/gogf/gf/v2@v2.7.1/os/gtimer/gtimer_entry.go:55 +0x12e
panic({0x1889f60?, 0x21cc9c0?})
/usr/local/go/src/runtime/panic.go:914 +0x21f
lx_saas/internal/cmd.glob..func1.1.1({0x1ba3e38?, 0xc0005a3110})
/Users/x/GolandProjects/lx_saas/internal/cmd/cmd.go:48 +0xfe
github.com/gogf/gf/v2/os/gtimer.(*Entry).Run.func1()
/Users/x/go/pkg/mod/github.com/gogf/gf/v2@v2.7.1/os/gtimer/gtimer_entry.go:66 +0x54
created by github.com/gogf/gf/v2/os/gtimer.(*Entry).Run in goroutine 34
/Users/x/go/pkg/mod/github.com/gogf/gf/v2@v2.7.1/os/gtimer/gtimer_entry.go:48 +0x79

What did you expect to see?

预期是 grpool.AddWithRecover 能捕获panic,但是实际是 gtimer.SetInterval 使用了原生协程处理无法捕获

@fainc fainc added the bug It is confirmed a bug, but don't worry, we'll handle it. label May 17, 2024
@fainc fainc changed the title is/grpool: AddWithRecover Panic os/grpool: AddWithRecover Panic May 17, 2024
@fainc
Copy link
Contributor Author

fainc commented May 17, 2024

grpool.AddWithRecover 内 第二层 gtimer.SetInterval 里的错误无法捕获(正常,内部使用go func 实现),所以是gtimer需要改成 grpool.AddWithRecover 实现?还是文档备注一下 grpool.AddWithRecover 只能捕获第一层的panic错误,里层的不管

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The error in the second layer gtimer.SetInterval in grpool.AddWithRecover cannot be captured (normal, internally implemented using go func), so gtimer needs to be changed to grpool.AddWithRecover? Let me make a note in the documentation: grpool.AddWithRecover can only capture panic errors in the first layer, and does not care about panic errors in the lower layers.

@hailaz
Copy link
Member

hailaz commented May 23, 2024

异常是不能捕获协程的panic的,这是语言本身决定的。
ba7eeb4a1da7eac208a0baeeda95162

@hailaz hailaz closed this as completed May 23, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Exceptions cannot capture the panic of the coroutine, which is determined by the language itself.
ba7eeb4a1da7eac208a0baeeda95162

@hailaz hailaz added question and removed bug It is confirmed a bug, but don't worry, we'll handle it. labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants