Spring Webflux WebClient记录``对等重置连接'' [英] Spring webflux WebClient logs 'Connection reset by peer'
问题描述
我有以下使用WebClient进行HTTP调用的代码.
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))));
一段时间(例如10分钟)后第一次调用此代码,我得到以下日志.但是,调用成功,输出正确.
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
不确定为什么会生成这些日志.当我使用SpringBoot 2.1.0时,它以ERROR级别登录,现在我升级到2.1.3版本(反应器净值版本-0.8.5),并且以WARN级别登录.我应该担心这些日志吗?
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?
推荐答案
当客户端连接一次并且下一个请求失败-然后重试时,客户端消失(反弹)时,我看到了类似的行为.
I have seen similar behavior when the client goes away (bounced) after connecting to it once and the next request fails - then retries.
在创建WebClient时尝试禁用连接池.像这样:
Try disabling connection pooling when creating the WebClient. Something like this:
@Bean
public WebClient webClient() {
return WebClient.builder()
.clientConnector(connector())
.build();
}
private ClientHttpConnector connector() {
return new ReactorClientHttpConnector(HttpClient.from(TcpClient.newConnection()));
}
这篇关于Spring Webflux WebClient记录``对等重置连接''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!