I am trying to figure out why my Microservice A get stuck at a POST call restTemplate.postForEntity whenever that request takes longer than 10-15 minutes and never proceeds further to LOG.info.
This happens even though it seems that all jobs have been completed in Microservice B, by first confirming all jobs have been run inside jobService::executeJob, and also that all of the LOG.info code have been reached. But then it hangs somewhere and prevents Microservice A from going further.
Since this only happens to heavy POST calls, I haven't been able to recreate this problem in the debugger.
- I use a default RestTemplate with an infinite timeout
- This works completely fine for lighter POST calls under a few minutes
Microservice A
public void doJobs(Collection<Job> jobs) {
restTemplate.postForEntity("http://localhost:8080/jobs", jobs, Void.class);
LOG.info("Jobs done");
}
Microservice B
@PostMapping(value = "/jobs")
public void post(@RequestBody Collection<Job> jobs) {
ForkJoinPool forkJoinPool = null;
try {
forkJoinPool = new ForkJoinPool(3);
forkJoinPool.submit(() -> jobs.parallelStream().forEach(jobService::executeJob)).get()
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error doing jobs", e);
throw new RuntimeException(e);
} catch (Exception e) {
LOG.error("Unknown error occurred", e);
throw e;
} finally {
LOG.info("Checking if fork join pool still active, shutting down if yes");
if (forkJoinPool != null) {
LOG.info("Shutting down fork join pool...");
forkJoinPool.shutdown();
}
}
LOG.info("Jobs completed, fork join pool successfully shut down");
}
Any idea what has gone wrong here?