I have a controller method returning Mono with a timeout operator. However default 30s timeout in Tomcat is applied, I can configure it globally, but in this case it should be per-request.

My current workaround is executing the following code before returning the value.

WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(servletRequest);
asyncManager.registerDeferredResultInterceptor("SET_TIMEOUT", new DeferredResultProcessingInterceptor() {
  @Override
  public <T> void preProcess(NativeWebRequest request, DeferredResult<T> deferredResult) {
    final HttpServletRequest servletRequest = (HttpServletRequest) request.getNativeRequest();
    servletRequest.getAsyncContext().setTimeout(timeout);
  }
});

Comment From: rstoyanchev

We could expose a setTimeout method directly on WebAsyncManager.

Comment From: panchenko

Is it feasible to detect if Mono already has timeout?

Comment From: rstoyanchev

Not that I know of.

So in your case the timeout on the Mono is substantially longer? In other words you can't set the global timeout to some different (max) value, and then customize it per endpoint to bring it down. Or if there is a way to sub-divide the URL space into different default timeout values then you could register an interceptor (via AsyncSupportConfigurer) to do that.

Comment From: rstoyanchev

Closing due to inactivity.