mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-25 23:15:51 +03:00
[GH-ISSUE #201] [BUG] panic in handler function is not caught #2093
Labels
No labels
CLI
bug
designing
documentation
duplicate
enhancement
good first issue
good first issue
help wanted
idea
invalid
investigate
needs-more-info
performance
pr-welcome
pull-request
question
wontfix
work in progress
work in progress
work-around-available
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asynq#2093
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rverton on GitHub (Sep 27, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/201
Originally assigned to: @hibiken on GitHub.
After a long time debugging why my tasks just fail without me giving any hint why, I noticed that some code in my handler result in a runtime panic. I found this commit here which should catch panics in handler as I understood, but it does not. The job just fails and is put into the retry queue.
To Reproduce
My code is like this:
Running this, I see
beforeprinted, but thats it. Nothing happens after this (and I can see withasynq statsthat the task failed).Expected behavior
The runtime panic should be converted to an error and returned.
Environment (please complete the following information):
@rverton commented on GitHub (Sep 27, 2020):
I just noticed that I'm also not able to catch a regular error in my logging middleware. Am I doing something wrong here? What is the common way to handle errors in handlers/logging them?
@hibiken commented on GitHub (Sep 27, 2020):
@rverton Thank you for opening this issue.
The
loggingMiddlewareyou provided seems fine, it should be catching errors returned from your Handler. I will look into that. As for the panic case, the middleware cannot catch that case with the current implementation. I may look into a way to enable that or I can simply clarify this in the documentation.For error handling, there's a specific handler called
ErrorHandlerwhich should be invoked whenever theHandlerreturns an error or panics.You can provide
ErrorHandlerin theConfigto handle errors.Let me know if this works for you :)
@rverton commented on GitHub (Sep 28, 2020):
Hey @hibiken,
thanks for the fast response. Awesome, defining the
ErrorHandlerin the server config allows me to print all occurred errors. It also did catch the runtime panic caused in my handler! I found the example code here now but did not know there is even a config option for this. Maybe you can add a hint in the docs for this, because it's hard to see why a handler fails when the default behavior is to be silent when an error occurred.Thanks for your project and help!