V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
heliotrope
V2EX  ›  Java

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

  •  
  •   heliotrope · 6 天前 · 629 次点击

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

    WebClient 之前是已经进入到等待响应了
    我是在服务方下了个断点卡在那边
    D3EP
        6
    D3EP  
       1 天前
    最容易忽略的就是 onCancel 了..
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   3499 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 10:03 · PVG 18:03 · LAX 02:03 · JFK 05:03
    ♥ Do have faith in what you're doing.