Skip to content

Commit

Permalink
Fix race condition in PartGenerator
Browse files Browse the repository at this point in the history
This commit fixes a race condition in PartGenerator, used by
DefaultPartHttpMessageReader. The condition can occur when a
completion signal comes in, and the state is changed to IdleFileState
at the same time.

Closes gh-28963
  • Loading branch information
poutsma committed Aug 30, 2022
1 parent 2c75eb8 commit 4c0ece9
Showing 1 changed file with 16 additions and 7 deletions.
Expand Up @@ -746,8 +746,15 @@ public void body(DataBuffer dataBuffer) {

@Override
public void partComplete(boolean finalPart) {
this.completed = true;
this.finalPart = finalPart;
State state = PartGenerator.this.state.get();
// writeComplete might have changed our state to IdleFileState
if (state != this) {
state.partComplete(finalPart);
}
else {
this.completed = true;
this.finalPart = finalPart;
}
}

public void writeBuffer(DataBuffer dataBuffer) {
Expand All @@ -771,14 +778,16 @@ public void writeBuffers(Iterable<DataBuffer> dataBuffers) {

private void writeComplete() {
IdleFileState newState = new IdleFileState(this);
if (this.completed) {
newState.partComplete(this.finalPart);
}
else if (this.disposed) {
if (this.disposed) {
newState.dispose();
}
else if (changeState(this, newState)) {
requestToken();
if (this.completed) {
newState.partComplete(this.finalPart);
}
else {
requestToken();
}
}
else {
MultipartUtils.closeChannel(this.channel);
Expand Down

0 comments on commit 4c0ece9

Please sign in to comment.