2

I have this following code which uses WebClient to make HTTP calls.

        webClient.post()
                 .uri("/users/track")
                 .body(BodyInserters.fromObject(getUserTrackPayload(selection, customAttribute, partyId).toString()))
                 .header(CONTENT_TYPE, APPLICATION_JSON)
                 .retrieve()
                 .onStatus(httpStatus -> !CREATED.equals(httpStatus),
                           response -> response.bodyToMono(String.class)
                                               .flatMap(body -> buildErrorMessage(response.statusCode().value(), body, partyId,
                                                                                  customAttribute)
                                                   .flatMap(e -> Mono.error(new MyException(e)))))
                 .bodyToMono(Object.class)
                 .map(o -> (JsonObject)new Gson().toJsonTree(o))
                 .flatMap(body -> body.get("message") != null && body.get("message").getAsString().equalsIgnoreCase("success")
                                  && body.get("attributes_processed") != null && body.get("attributes_processed").getAsInt() == 1
                     ? Mono.just(body)
                     : buildErrorMessage(CREATED.value(), body.toString(), partyId, customAttribute)
                         .flatMap(e -> Mono.error(new MyException(e))));

I am getting the following logs the first time this code is called after some time (like 10 minutes). But, the call is succeeding with the right output.

io.netty.channel.unix.Errors$NativeIoException: syscall:read(..) failed: Connection reset by peer at io.netty.channel.unix.FileDescriptor.readAddress(..)(Unknown Source)
2019-03-19 03:11:45,625 WARN  [:::] [reactor-http-epoll-8] reactor.netty.http.client.HttpClientConnect : [id: 0x2e3252c0, L:/172.18.0.125:42956 - R:my-endpoint.com/151.101.53.208:443] The connection observed an error

Not sure why these logs are getting generated. When I was using SpringBoot 2.1.0, it was logging in ERROR level, now I upgraded to 2.1.3 version (reactor netty version - 0.8.5) and it is logging in WARN level. Should I be worried about these logs?

4

1 回答 1

2

当客户端在连接一次后离开(反弹)并且下一个请求失败时,我看到了类似的行为 - 然后重试。

在创建 WebClient 时尝试禁用连接池。像这样的东西:

@Bean
public WebClient webClient() {
    return WebClient.builder()
             .clientConnector(connector())
             .build();
}

private ClientHttpConnector connector() {
    return new ReactorClientHttpConnector(HttpClient.from(TcpClient.newConnection()));
}
于 2019-10-18T18:04:58.640 回答