-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Opt in PanicHandler #646
Opt in PanicHandler #646
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ type workerPool struct { | |
|
||
LogAllErrors bool | ||
|
||
PanicHandler func(r interface{}) | ||
|
||
MaxIdleWorkerDuration time.Duration | ||
|
||
Logger Logger | ||
|
@@ -200,9 +202,27 @@ func (wp *workerPool) release(ch *workerChan) bool { | |
return true | ||
} | ||
|
||
func (wp *workerPool) workerDone() { | ||
wp.lock.Lock() | ||
wp.workersCount-- | ||
wp.lock.Unlock() | ||
} | ||
|
||
func (wp *workerPool) workerFunc(ch *workerChan) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like that this change will silently affect users with PanicHandler == nil as well.
JNZ FUNCRET;
JMP WORKER_DONE;
FUNCRET: and that's all while the user doesn't even use this feature. while I understand what (*wp).workerDone() is easier to read in the context of this feature, I'm not sure that this feature is really required, or at least that this implementation is optimal for both users who want the PanicHandler and who don't. Again, I use fasthttp for several years now and I still didn't find a case when fasthttp would panic. I'd like to hear some more thoughts about this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think it's better if we just handle panics from For people who want more control it's not that hard to wrap the reader and handle these panics themselves. This way we don't expose any extra API again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the above. Moreover, #687 is definitely a step in the right direction for us. So closing this one. |
||
var c net.Conn | ||
|
||
if wp.PanicHandler != nil { | ||
defer func() { | ||
wp.workerDone() | ||
if r := recover(); r != nil { | ||
if c != nil { | ||
c.Close() | ||
} | ||
wp.PanicHandler(r) | ||
} | ||
}() | ||
} | ||
|
||
var err error | ||
for c = range ch.ch { | ||
if c == nil { | ||
|
@@ -231,7 +251,7 @@ func (wp *workerPool) workerFunc(ch *workerChan) { | |
} | ||
} | ||
|
||
wp.lock.Lock() | ||
wp.workersCount-- | ||
wp.lock.Unlock() | ||
if wp.PanicHandler == nil { | ||
wp.workerDone() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this r shadows io.Reader defined above. I think we should rename this variable