【发布时间】:2022-01-25 00:48:28
【问题描述】:
在我的团队管理的一个应用程序中,有一个调用下游服务的 GraphQL 编排层。 我们使用 Spring 的 webclient。
WebClient 配置。
WebClient.Builder webClientBuilder(MetricsWebClientCustomizer metricsCustomizer) {
final HttpClient httpClient = HttpClient.create(ConnectionProvider.fixed("webClientPool", maxConnections))
.tcpConfiguration(client ->
client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis)
.option(EpollChannelOption.TCP_KEEPIDLE, tcpKeepIdleInSec)
.option(EpollChannelOption.TCP_KEEPINTVL, tcpKeepIntvlInSec)
.option(EpollChannelOption.TCP_KEEPCNT, tcpKeepCount)
.doOnConnected(conn -> conn
.addHandlerLast(new ReadTimeoutHandler(readTimeoutInSec))
));
final WebClient.Builder webClient = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient));
metricsCustomizer.customize(webClient);
return webClient;
}
return client.post()
.uri(uriBuilder -> buildUri())
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromObject(request))
.retrieve()
.bodyToMono(Result.class)
.compose(CircuitBreakerOperator.of(cb))
.block(Duration.ofSeconds(blockDuration));
此设置运行良好。但是,我看到了很多
io.netty.handler.timeout.ReadTimeoutException: null
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher. .blockingGet(BlockingSingleSubscriber.java:133)
at reactor.core.publisher.Mono.block(Mono.java:1518)
at com.xxxx.c.g.xx.client.Client.get(Client.java:293)
at com.xxxx.c.g.xx.resolver.impl.xxQueryImpl.lambda$xx$171(xxQueryImpl.java:2187)
at io.micrometer.core.instrument.AbstractTimer.record(AbstractTimer.java:149)
每次超时都会导致这个大块堆栈跟踪。这是重复的相同消息。确实提供任何有用的信息。有没有办法让 WebClient/Netty 打印一次并忽略其余部分?
BlockingSingleSubscriber.blockingGet 似乎正在这样做。跟踪以前的异常。
Throwable e = this.error;
if (e != null) {
RuntimeException re = Exceptions.propagate(e);
re.addSuppressed(new Exception("#block terminated with an error"));
throw re;
} else {
return this.value;
}
我尝试将错误处理程序添加到调用函数bodyToMono(Result.class).doOnError("log").block();
这会导致 doOnError 消费者的“日志”行与厚实的堆栈跟踪一起打印。
有什么想法吗?
完整的堆栈跟踪: https://pastebin.com/kdpspCEY
【问题讨论】:
标签: spring spring-webclient reactor-netty