Skip to content

Commit

Permalink
Fix multipart async servlet request temporary files deletion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simonbasle committed Jul 12, 2024
1 parent 0f3f979 commit 152914a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public final class WebAsyncManager {

private AsyncTaskExecutor taskExecutor = DEFAULT_TASK_EXECUTOR;

private boolean isMultipartRequestParsed;

@Nullable
private volatile Object concurrentResult = RESULT_NONE;

Expand Down Expand Up @@ -242,6 +244,24 @@ public void registerDeferredResultInterceptors(DeferredResultProcessingIntercept
}
}

/**
* Mark the {@link WebAsyncManager} as wrapping a
* multipart async request.
* @since 6.1.12
*/
public void setMultipartRequestParsed(boolean isMultipart) {
this.isMultipartRequestParsed = isMultipart;
}

/**
* Return {@code true} if this {@link WebAsyncManager} was previously marked
* as wrapping a multipart async request, {@code false} otherwise.
* @since 6.1.12
*/
public boolean isMultipartRequestParsed() {
return this.isMultipartRequestParsed;
}

/**
* Clear {@linkplain #getConcurrentResult() concurrentResult} and
* {@linkplain #getConcurrentResultContext() concurrentResultContext}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,11 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
if (mappedHandler != null) {
mappedHandler.applyAfterConcurrentHandlingStarted(processedRequest, response);
}
asyncManager.setMultipartRequestParsed(multipartRequestParsed);
}
else {
// Clean up any resources used by a multipart request.
if (multipartRequestParsed) {
if (multipartRequestParsed || asyncManager.isMultipartRequestParsed()) {
cleanupMultipart(processedRequest);
}
}
Expand Down

0 comments on commit 152914a

Please sign in to comment.