I'm trying to get a StreamingResponseBody from a @RestController on a long running job. It times out after 30 seconds, no matter what configuration I try.
This is in Spring Boot 2.0.3. I've used the below test which shows the same behavior to try and get the configuration correct.
@RestController
public class TestController {
@RequestMapping("/streamtest")
public StreamingResponseBody handleRequest () {
return new StreamingResponseBody() {
@Override
public void writeTo (OutputStream out) throws IOException {
for (int i = 0; i < 100000; i++) {
out.write((Integer.toString(i) + " - ").getBytes());
out.flush();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
}
}
I've tried the async.request-timeout setting defined here; Async timeout downloading a large file using StreamingResponseBody on Spring Boot
I've tried overriding WebMvcConfig to set the timeout. This method is never called.
@EnableWebMvc
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(3600000);
WebMvcConfigurer.super.configureAsyncSupport(configurer);
}
}
I've tried defining the ThreadPoolTaskExecutor:
@Configuration
@EnableAsync
@EnableScheduling
public class AsyncConfig implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
return new ThreadPoolTaskExecutor();
}
}
It always times out after 30 seconds with a log;
12:14:28.028 [http-nio-8080-exec-2] DEBUG c.b.b.bof_static.config.BofStaticExceptionHandler - Async timeout for GET [/streamtest]
12:14:28.028 [http-nio-8080-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
12:14:28.028 [http-nio-8080-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
12:14:28.030 [http-nio-8080-exec-2] DEBUG o.s.security.web.access.ExceptionTranslationFilter - Chain processed normally
I'm unable to find any other solutions. Can anyone point out what's missing?