From 46329851c1f4a4a7dab48380580152bd90644047 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 27 Oct 2022 11:50:40 +0200 Subject: [PATCH] Ensure state of PartGenerator accepts buffers This commit makes sure that the current state of the PartGenerator is able to handle an incoming buffer, possibly requested because of a request coming from the subscription. All states accept new buffers except the WritingFileState. Closes gh-29227 --- .../http/codec/multipart/PartGenerator.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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;