Skip to content

Sentinel object Magazine.MAGAZINE_FREED is possible be replaced without be restored back #14498

@laosijikaichele

Description

@laosijikaichele

Expected behavior

If I understood it right, the sentinel object Magazine.MAGAZINE_FREED should not be replaced without being restored back.

Actual behavior

private void transferChunk(Chunk current) {
if (NEXT_IN_LINE.compareAndSet(this, null, current)
|| parent.offerToQueue(current)) {
return;
}
Chunk nextChunk = NEXT_IN_LINE.get(this);
if (nextChunk != null && current.remainingCapacity() > nextChunk.remainingCapacity()) {
if (NEXT_IN_LINE.compareAndSet(this, nextChunk, current)) {
if (nextChunk != MAGAZINE_FREED) {
nextChunk.release();
}
return;
}
}
// Next-in-line is occupied AND the central queue is full.
// Rare that we should get here, but we'll only do one allocation out of this chunk, then.
current.release();
}

The line:671 Chunk nextChunk = NEXT_IN_LINE.get(this); if nextChunk get value MAGAZINE_FREED, which is possible when magazines table is doing resizing, then the line:673 NEXT_IN_LINE.compareAndSet(this, nextChunk, current) will replace the MAGAZINE_FREED object by current, and without restored the MAGAZINE_FREED back.

Possible solution:

Modified line:672 to:

if (nextChunk != null && nextChunk != MAGAZINE_FREED 
&& current.remainingCapacity() > nextChunk.remainingCapacity()) {
...
}

Netty version

4.1.115.Final

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions