简体   繁体   English

Spring webflux WebClient 记录“对等方重置连接”

[英]Spring webflux WebClient logs 'Connection reset by peer'

I have this following code which uses WebClient to make HTTP calls.我有以下代码,它使用 WebClient 进行 HTTP 调用。

        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).一段时间(如 10 分钟)后第一次调用此代码时,我收到以下日志。 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.当我使用 SpringBoot 2.1.0 时,它登录到 ERROR 级别,现在我升级到 2.1.3 版本(reactor netty 版本 - 0.8.5)并且它登录到 WARN 级别。 Should I be worried about these logs?我应该担心这些日志吗?

I have seen similar behavior when the client goes away (bounced) after connecting to it once and the next request fails - then retries.当客户端在连接一次后消失(反弹)并且下一个请求失败时,我看到了类似的行为 - 然后重试。

Try disabling connection pooling when creating the WebClient.在创建 WebClient 时尝试禁用连接池。 Something like this:像这样的东西:

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

private ClientHttpConnector connector() {
    return new ReactorClientHttpConnector(HttpClient.from(TcpClient.newConnection()));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM