Set prev
to null when setting cursor
to head
in scavengeSome
.
Motivation:
`scavengeSome()` has a corner case: when setting `cursor` to `head`, `this.prev` may point to the tail of the `WeakOrderQueue` linked list. Then it's possible that the following while loop will link the tail to the head, and cause endless loop.
I made a reproducer in 36522e7b72
. The unit test will just run forever. Unfortunately, I cannot change it to a unit test because it needs to add some codes to `scavengeSome` to control the execution flow.
Modification:
Set `prev` to null when setting `cursor` to `head` in `scavengeSome`
Result:
Fixes #6153.
This commit is contained in:
parent
a8950dfc4c
commit
2457f386d8
@ -479,16 +479,19 @@ public abstract class Recycler<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean scavengeSome() {
|
boolean scavengeSome() {
|
||||||
|
WeakOrderQueue prev;
|
||||||
WeakOrderQueue cursor = this.cursor;
|
WeakOrderQueue cursor = this.cursor;
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
|
prev = null;
|
||||||
cursor = head;
|
cursor = head;
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
prev = this.prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
WeakOrderQueue prev = this.prev;
|
|
||||||
do {
|
do {
|
||||||
if (cursor.transfer(this)) {
|
if (cursor.transfer(this)) {
|
||||||
success = true;
|
success = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user