diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java index 0d82ee3449..214d37e009 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java @@ -688,6 +688,16 @@ final class PartGenerator extends BaseSubscriber { @Override public void onComplete() { this.completed = true; + public void partComplete(boolean 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) { @@ -711,14 +721,16 @@ final class PartGenerator extends BaseSubscriber { private void writeComplete() { IdleFileState newState = new IdleFileState(this); - if (this.completed) { - newState.onComplete(); - } - 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);