-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
About NullPointerException in Recycles #355
Conversation
CLA is required @Devyun |
And can you add some unit test? |
ok |
CLA is required @Devyun |
I have signed this CLA. but clahub is still show X |
ut is failed @Devyun |
May be we can refer netty/netty@338ef96#diff-b7c5624e42938616f2c51f7115340ae0R84 |
|
||
Stack<?> stack = this.stack; | ||
if ( lastRecycledId != recycleId || stack == null) { | ||
throw new IllegalStateException("recycled already"); |
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.
同上
jraft-core/src/main/java/com/alipay/sofa/jraft/util/Recyclers.java
Outdated
Show resolved
Hide resolved
jraft-core/src/main/java/com/alipay/sofa/jraft/util/Recyclers.java
Outdated
Show resolved
Hide resolved
@@ -326,7 +329,8 @@ DefaultHandle pop() { | |||
size--; | |||
DefaultHandle ret = elements[size]; | |||
if (ret.lastRecycledId != ret.recycleId) { | |||
throw new IllegalStateException("recycled multiple times"); | |||
LOG.warn("recycled already"); | |||
return null; |
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.
pop 出现 (ret.lastRecycledId != ret.recycleId) 的情况应该是 recycle 逻辑有问题,这里并不是事故第一现场,并且这里 DefaultHandle 也没有做一些释放处理,所以我建议这里就维持刨出异常
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.
确实
需要改一下原有的单侧: testMultipleRecycle |
好的 |
@Devyun Please rebase this branch with master. |
I'm done |
@Devyun 改为如下逻辑:
|
如果要assertFalse(object.recycle());成立的话,需要改push和DefaultHandle#recycle的返回值,要改吗? |
牵一发动全身,我觉得我们可能错了 @killme2008 ,现在我更倾向于维持原有的抛出异常的策略,本身重复 recycle() 就是个严重的错误行为,应该禁止,没必要在这里为用户的错误行为容错 |
@@ -133,6 +140,13 @@ public final int threadLocalSize() { | |||
|
|||
public void recycle() { | |||
Thread thread = Thread.currentThread(); | |||
|
|||
final Stack<?> stack = this.stack; | |||
if ( lastRecycledId != recycleId || stack == null) { |
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.
这一行代码格式要调整下, lastRecycledId 前边不应该有空格,recycleId 前边有两个空格,应该改为一个
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.
喜欢有代码洁癖的人,哈哈哈
@Devyun 我觉得要么我们还是恢复抛出异常? 也方便跟进 netty 原版 code 持续更新 |
好滴~ |
* 'master' of https://github.com/sofastack/sofa-jraft: Feature/some changes (sofastack#358) fix elect priority (sofastack#357) Remove unused imports (sofastack#356) feat/priority_by_zongtanghu (sofastack#345)
@Devyun tks |
Motivation:
issue : #353
Modification:
Describe the idea and modifications you've done.
Result:
Fixes #.
If there is no issue then describe the changes introduced by this PR.