'PortUnreachableException when trying to delay http response on backend side

i use spring webflux and wanna understand what's going on. To make my tests, i use a backend side as provider and a backend side as consumer

as consumer, i have a code something like that..

 RequestHeadersSpec<?> q = webclient
  .get()
  .uri(breakdownEndpoint, vars)
  .header(HttpHeaders.AUTHORIZATION, eprBearer)
  .accept(MediaType.APPLICATION_JSON);

return q.exchangeToMono(r -> {

  if (r.statusCode() == HttpStatus.OK) {
    return r.bodyToMono(new ParameterizedTypeReference<List<StockJobStatisticBreakdownDto>>() {
    });
  } else if (r.statusCode() == HttpStatus.NOT_FOUND) {
    logger.error("unable to find uri..");
    return Mono.empty();
  } 
}).block(Duration.ofMinutes(5));

All is well, BUT, when i install a delay on a provider side, something like that..

  @GetMapping("/stocks/")
  public ResponseEntity<?> stockJobStatisticBreakdown() {

  // some code

 try {
 Thread.sleep(1000 * 20);
 } catch (InterruptedException e) {
 }

return ResponseEntity.ok(breakdown);

}

then, i got, on a consumer side, this exception..

  R:localhost/127.0.0.1:8125] java.net.PortUnreachableException: ..

Why this kind of exception (unreachable) ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source