Skip to content

Commit 152914a

Browse files
committed
Fix multipart async servlet request temporary files deletion
This change tracks the multipart nature of the async request within the `DispatcherServlet`, in the `WebAsyncManager`. This allows for the second ASYNC dispatch to recognize the multipart aspect and clean up the associated resources. Closes gh-33161
1 parent 0f3f979 commit 152914a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java

+20
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public final class WebAsyncManager {
7979

8080
private AsyncTaskExecutor taskExecutor = DEFAULT_TASK_EXECUTOR;
8181

82+
private boolean isMultipartRequestParsed;
83+
8284
@Nullable
8385
private volatile Object concurrentResult = RESULT_NONE;
8486

@@ -242,6 +244,24 @@ public void registerDeferredResultInterceptors(DeferredResultProcessingIntercept
242244
}
243245
}
244246

247+
/**
248+
* Mark the {@link WebAsyncManager} as wrapping a
249+
* multipart async request.
250+
* @since 6.1.12
251+
*/
252+
public void setMultipartRequestParsed(boolean isMultipart) {
253+
this.isMultipartRequestParsed = isMultipart;
254+
}
255+
256+
/**
257+
* Return {@code true} if this {@link WebAsyncManager} was previously marked
258+
* as wrapping a multipart async request, {@code false} otherwise.
259+
* @since 6.1.12
260+
*/
261+
public boolean isMultipartRequestParsed() {
262+
return this.isMultipartRequestParsed;
263+
}
264+
245265
/**
246266
* Clear {@linkplain #getConcurrentResult() concurrentResult} and
247267
* {@linkplain #getConcurrentResultContext() concurrentResultContext}.

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,11 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
11181118
if (mappedHandler != null) {
11191119
mappedHandler.applyAfterConcurrentHandlingStarted(processedRequest, response);
11201120
}
1121+
asyncManager.setMultipartRequestParsed(multipartRequestParsed);
11211122
}
11221123
else {
11231124
// Clean up any resources used by a multipart request.
1124-
if (multipartRequestParsed) {
1125+
if (multipartRequestParsed || asyncManager.isMultipartRequestParsed()) {
11251126
cleanupMultipart(processedRequest);
11261127
}
11271128
}

0 commit comments

Comments
 (0)