Skip to content

[Question]: About what happens when panic occurred inside a worker #364

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

Closed
vvakame opened this issue Apr 11, 2025 · 2 comments · Fixed by #365
Closed

[Question]: About what happens when panic occurred inside a worker #364

vvakame opened this issue Apr 11, 2025 · 2 comments · Fixed by #365
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@vvakame
Copy link

vvakame commented Apr 11, 2025

Questions with details

Hi! My team uses ants a lot. Thanks for a great product!

Document of Options.PanicHandler said below 1

if nil, panics will be thrown out again from worker goroutines.

In the actual implementation, if PanicHandler is nil, it appears to be suppressed after logging output. 2

If I want to detect a panic (or propagate panic to main process) after Invoke called, should I use WithPanicHandler with own implementations?

Code snippets (optional)

Footnotes

  1. https://github.com/panjf2000/ants/blob/a44594205e16818434d27f02da3f81c26e51a74a/options.go#L57-L58

  2. https://github.com/panjf2000/ants/blob/a44594205e16818434d27f02da3f81c26e51a74a/worker_func.go#L62

@vvakame vvakame added help wanted Extra attention is needed question Further information is requested labels Apr 11, 2025
@panjf2000
Copy link
Owner

WithPanicHandler was first introduced by #23 and the behavior matched the docs, but the behavior had been changed since this commit and I forgot to update the docs. Thanks for pointing it out!

If I want to detect a panic (or propagate panic to main process) after Invoke called, should I use WithPanicHandler with own implementations?

As for your use case, yes, you can call panic in your PanicHandler.

@vvakame
Copy link
Author

vvakame commented Apr 14, 2025

thanks to explanations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants