Unexpected 504 Gateway Timeout on Long-Running Spring Boot REST API Task
I'm converting an old project and After trying multiple solutions online, I still can't figure this out. I'm working with a **504 Gateway Timeout** behavior when trying to execute a long-running task via a Spring Boot REST API. I have a service that processes a large dataset and can take a few minutes to complete. When I make a POST request to start this process, it seems that the server is timing out before the task can finish. I've tried increasing the timeout settings in both my Spring Boot application and the Nginx reverse proxy that sits in front of it, but the scenario continues. Hereโs how Iโm currently making the POST request: ```java @RestController @RequestMapping("/api/tasks") public class TaskController { @Autowired private TaskService taskService; @PostMapping("/process") public ResponseEntity<String> startProcessing(@RequestBody DataRequest dataRequest) { taskService.processData(dataRequest); return ResponseEntity.accepted().body("Processing started"); } } ``` In my service, I perform the actual processing: ```java @Service public class TaskService { public void processData(DataRequest dataRequest) { // Simulating a long-running task try { Thread.sleep(300000); // 5 minutes } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } ``` Iโve configured Nginx to have a higher timeout as follows: ```nginx location /api/ { proxy_pass http://localhost:8080; proxy_read_timeout 600s; proxy_connect_timeout 600s; } ``` And in my `application.properties`, Iโve set: ``` spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-request-size=10MB server.tomcat.connection-timeout=60000 ``` Even with these settings, I still receive a 504 behavior when the task runs longer than expected. Can anyone guide to understand what might be going wrong or how I can handle long-running processes in a RESTful way without hitting these timeout limits? My development environment is Windows 11. Any pointers in the right direction? Has anyone dealt with something similar?