-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix a bug that doesn't release lock #79
Conversation
err!=nil时未释放锁,使用defer p.lock.Unlock()修复
Codecov Report
@@ Coverage Diff @@
## master #79 +/- ##
==========================================
+ Coverage 95.61% 95.66% +0.05%
==========================================
Files 8 8
Lines 524 531 +7
==========================================
+ Hits 501 508 +7
Misses 16 16
Partials 7 7
Continue to review full report at Codecov.
|
pool.go
Outdated
@@ -247,6 +247,7 @@ func (p *Pool) revertWorker(worker *goWorker) bool { | |||
} | |||
worker.recycleTime = time.Now() | |||
p.lock.Lock() | |||
defer p.lock.Unlock() |
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.
在这种性能极度敏感的库代码里尽量不要用 defer,它在汇编层面会有很多连锁调用导致性能损耗。直接在下面的 if err != nil {}
里面加一个解锁的步骤就行了。
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.
defer 在 1.14 基本已经没啥损耗了。另外即使是在老版本,大概率池子里运行的函数本身远重于 defer。这个池子本身的性能瓶颈也不会在这里。反倒是因为不用 defer,这已经是第二次碰到异常路径上没 unlock 的问题了。
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.
能看出具体是哪一步没 unlock 吗?
@panjf2000 这种 case 不加单测么? |
err!=nil时未释放锁,使用defer p.lock.Unlock()修复
name: Pull request
about: Propose changes to the code
title: ''
labels: ''
assignees: ''
1. Are you opening this pull request for bug-fixs, optimizations or new feature?
2. Please describe how these code changes achieve your intention.
3. Please link to the relevant issues (if any).
4. Which documentation changes (if any) need to be made/updated because of this PR?
4. Checklist