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 11ed75d9700f..f2dad5c90c26 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 @@ -229,6 +229,7 @@ void requestToken() { if (upstream() != null && !this.sink.isCancelled() && this.sink.requestedFromDownstream() > 0 && + this.state.get().canRequest() && this.requestOutstanding.compareAndSet(false, true)) { request(1); } @@ -291,6 +292,13 @@ private interface State { default void error(Throwable throwable) { } + /** + * Indicates whether the current state is ready to accept a new token. + */ + default boolean canRequest() { + return true; + } + /** * Cleans up any state. */ @@ -814,6 +822,11 @@ private Mono writeInternal(DataBuffer dataBuffer) { } } + @Override + public boolean canRequest() { + return false; + } + @Override public void dispose() { this.disposed = true;