Skip to content

Commit dc26d3b

Browse files
committed
Defer cleanup in DefaultServerWebExchange
This commit ensures that the multipartRead flag is read in a deferred block, and is not evaluated too early. Closes gh-31567
1 parent 7f94c64 commit dc26d3b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,20 @@ public Mono<MultiValueMap<String, Part>> getMultipartData() {
247247

248248
@Override
249249
public Mono<Void> cleanupMultipart() {
250-
if (this.multipartRead) {
251-
return getMultipartData()
252-
.onErrorResume(t -> Mono.empty()) // ignore errors reading multipart data
253-
.flatMapIterable(Map::values)
254-
.flatMapIterable(Function.identity())
255-
.flatMap(part -> part.delete()
256-
.onErrorResume(ex -> Mono.empty()))
257-
.then();
258-
}
259-
else {
260-
return Mono.empty();
261-
}
250+
return Mono.defer(() -> {
251+
if (this.multipartRead) {
252+
return getMultipartData()
253+
.onErrorComplete()
254+
.flatMapIterable(Map::values)
255+
.flatMapIterable(Function.identity())
256+
.flatMap(part -> part.delete()
257+
.onErrorComplete())
258+
.then();
259+
}
260+
else {
261+
return Mono.empty();
262+
}
263+
});
262264
}
263265

264266
@Override

0 commit comments

Comments
 (0)