V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
heliotrope
V2EX  ›  Java

WebFlux 项目 被访问后 访问方关闭连接 无法捕获 SocketException: Connection reset

  •  
  •   heliotrope · Feb 4 · 1621 views
    This topic created in 94 days ago, the information mentioned may be changed or developed.

    程序 A 请求方 程序 B WebFlux 写的网关 程序 C 服务方

    请求方 请求 网关时 超时设置 10 秒 网关设置超时 60 秒 服务方 响应需要 10 秒以上 出现一个问题

    网关中使用 WebClient 转发请求到服务方时 当请求方因为 10 秒超时关闭链接 网关只会输出 '''reactor.netty.channel.FluxReceive [0;39m - [warn,299] - [36m[ce92646a-2, L:/192.168.101.233:9195 - R:/192.168.101.233:50853] An exception has been observed post termination, use DEBUG level to see the full stack: java.net.SocketException: Connection reset'''

    还只是 WARN 网关中 WebClient 写的 doOnError doFinally 都不会触发 网关的 ErrorWebExceptionHandler 也拦截不到这个异常

    相当于无法记录这个请求被请求方关闭了 整个进程被 kill 掉了一样 没法做任何操作

    求教 如何捕获这个 Connection reset

    6 replies    2026-02-09 16:44:45 +08:00
    chocotan
        1
    chocotan  
       Feb 4
    试试 doOnCancel
    heliotrope
        2
    heliotrope  
    OP
       Feb 4
    @chocotan 没有进...
    在 WebClient 上加了不行
    在 WebFilterChain 上加了也没调用
    chocotan
        3
    chocotan  
       Feb 4
    @heliotrope 网关 webClient 转发这一步进来没?
    感觉只能在这个异常的地方加断点,看下前后的调用链
    记录异常试试这个 filter: https://gist.github.com/chocotan/8d501e99a6ef1160077c1d59c43e2733
    chocotan
        4
    chocotan  
       Feb 4
    @chocotan onError 方法
    heliotrope
        5
    heliotrope  
    OP
       Feb 4
    @chocotan 感谢大佬
    添加这个 filter 可以进入 onCancel

    WebClient 之前是已经进入到等待响应了
    我是在服务方下了个断点卡在那边
    D3EP
        6
    D3EP  
       Feb 9
    最容易忽略的就是 onCancel 了..
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3014 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 02:42 · PVG 10:42 · LAX 19:42 · JFK 22:42
    ♥ Do have faith in what you're doing.