title: Webclient response handler (both success & error) does not execute for empty response body
body: <p>Have an async REST API client implemented with OkHttp, works just fine.
  Trying to convert it to WebClient out of curiosity, observing weird behaviour.</p>
  
  <p>WebClient configuration is just this:</p>
  
  <pre><code>webClient = WebClient.builder()
      .defaultHeaders(headers -&gt; headers.add(HttpHeaders.CONTENT_TYPE,
          org.springframework.http.MediaType.APPLICATION_JSON_VALUE))
      .clientConnector(new ReactorClientHttpConnector(builder -&gt; builder
          .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout)))
      .build();
  </code></pre>
  
  <p>request code:</p>
  
  <pre><code>void getTokenWithWebClient(Consumer&lt;Try&lt;String&gt;&gt; callback) {
      webClient.post()
          .uri(url)
          .syncBody(new MyRequest())
          .retrieve()
          .onStatus(status -&gt; status.value() != HttpStatus.OK.value(),
              rs -&gt; rs.bodyToMono(String.class).map(body -&gt; new IOException(String.format(
                  "Response HTTP code is different from 200: %s, body: '%s'", rs.statusCode(), body))))
          .bodyToMono(MyResponse.class)
          .subscribe(rs -&gt; callback.accept(Try.of(() -&gt; validateResponse(Option.of(rs)))),
              ex -&gt; callback.accept(Try.failure(ex)));
  }
  </code></pre>
  
  <p>In the unit test, callback that is passed as an argument to this method, completes a Future, on which I wait. 
  So, when I <strong>run</strong> the test in IDEA, and the request results in a response with empty body (content-length: 0), the lambdas in subscribe() never execute - verified using println debugging.</p>
  
  <p>But when I <strong>debug</strong> the same test, even without any breakpoints set, it completes as expected and the lambdas are invoked depending on the result.</p>
  
  <p>I do see this in the log:</p>
  
  <pre><code>[reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClientOperations - [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522] Received last HTTP packet
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClient - [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522] USER_EVENT: [Handler Terminated]
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.channel.ChannelOperationsHandler - [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522] Disposing context reactor.ipc.netty.channel.PooledClientContextHandler@3547abe3
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.channel.PooledClientContextHandler - Releasing channel: [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522]
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.resources.DefaultPoolResources - Released [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522], now 0 active connections
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClient - [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522] READ COMPLETE
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClient - [id: 0xeffaded6, L:/127.0.0.1:49265 - R:localhost/127.0.0.1:58522] READ COMPLETE
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClient - [id: 0xeffaded6, L:/127.0.0.1:49265 ! R:localhost/127.0.0.1:58522] CLOSE
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClient - [id: 0xeffaded6, L:/127.0.0.1:49265 ! R:localhost/127.0.0.1:58522] INACTIVE
  [reactor-http-nio-4] DEBUG reactor.ipc.netty.http.client.HttpClient - [id: 0xeffaded6, L:/127.0.0.1:49265 ! R:localhost/127.0.0.1:58522] UNREGISTERED
  </code></pre>
  
  <p>but then the Mono with my error gets stuck somewhere.</p>
  
  <p>Running this on Windows 7, Oracle JDK8 x64, IDEA 2018.
  Option/Try are vavr classes (io.vavr:vavr), not relevant for this case.
  For unit tests, I mock the REST API in question using Ratpack.</p>
  
  <p>Tried using exchange() instead of retrieve() and checking the status code in the subscribe() lambda, without onStatus() - with the same result.</p>
  
  <p>Any ideas?</p>