【问题标题】:suppress stacktrace from spring webclient/netty layer从 spring webclient/netty 层抑制堆栈跟踪
【发布时间】: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


    【解决方案1】:

    不确定您是否已经解决了这个问题,但我遇到了同样的问题。对于任何有类似问题的人,我通过在application.properties 文件中设置以下内容来解决它:

    # Logging Information
    logging.level.reactor.netty=off
    

    这禁用了 Reactor Netty 内部日志记录,这对于我的需要来说有点冗长。

    【讨论】:

      猜你喜欢
      • 2013-09-29
      • 2023-04-05
      • 1970-01-01
      • 2017-10-14
      • 2015-12-07
      • 2021-12-30
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多