Spring Boot - request timeout 504

Viewed 131

I have two Spring Boot REST application they talk with each other.

ProjectA, getTest rest service sometimes it takes a minute. It calls from projectB.

  @PostMapping(value = "/test")
  public ResponseEntity<Map<byte[], List<String>>> getTest(
      @RequestBody ObjectDTO configDto) {
    try {

      HashMap<byte[], List<String>> testMap =
          serviceImpl.test(configDto);

      if (!testMap.isEmpty())
        return new ResponseEntity<>(testMap, HttpStatus.CREATED);
      else return new ResponseEntity<>(testMap, HttpStatus.NO_CONTENT);

    } catch (Exception e) {      
      return ResponseEntity.badRequest().build();
    }
  }

ProjectB which calls the API above.

@PostMapping(value = "/getTest")
  @Async
  public ResponseEntity<Map<byte[], List<String>>> getTest(
      @RequestBody Config config) {
    try {
        Map<byte[], List<String>> val = serviceImpl.testConfig(config);
        return new ResponseEntity<>(val, HttpStatus.CREATED);       
    } catch (Exception e) {
      return ResponseEntity.badRequest().build();
    }
  }

It works locally but when I run on prod it always returns after 6.2s:

upstream request timeout

I have already increased the timeout on the properties with the config below on Project B, but did not work.

server.tomcat.connection-timeout=120000
spring.mvc.async.request-timeout=120000

so the question is how to fix a 504 Gateway Timeout Error

0 Answers
Related