接口调用遇到Unexpected EOF read on the socket异常问题处理

SpringBoot项目在接收参数时,突然出现Unexpected EOF read on the socket异常报错,此时请求还没有进入服务端,初步看起来是客户端的问题。

2022-06-10 11:53:36 [http-nio-10244-exec-3] WARN  o.s.w.s.m.support.DefaultHandlerExceptionResolver.logException 194 --> Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.io.EOFException: Unexpected EOF read on the socket]
2022-06-10 11:54:06 [http-nio-10244-exec-5] WARN  o.s.w.s.m.support.DefaultHandlerExceptionResolver.logException 194 --> Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.io.EOFException: Unexpected EOF read on the socket]

       进行Wireshark抓包查看HTTP请求报文,发现只有服务端响应报文,客户端请求报文丢失了。

        请求方式是POST请求参数是String类型,不应该出现接收不到的情况,部署在其他环境上是好的。

    @RequestMapping(value = "/getTest", method = RequestMethod.POST)
    public void getTest(@RequestBody String paramter) {
        log.info(paramter);
    }

        于是我又换了另外一种请求方式,使用request接收,然后通过读取reader的方式获取参数,此时仍然报错,但是查看读取到的数据里面是有参数的,只是参数不完整,无法解析通过JSON转换,此情况表示请求已经接收到了,但是由于某原因导致吧请求放弃停止了。

    @RequestMapping(value = "/getTest", method = RequestMethod.POST)
    public void getTest(HttpServletRequest request) {

        char[] lineChars = new char[1024 * 1024];
        char[] totalChars = new char[1024 * 1024];
        int readLen = 0;
        int totalLen = 0;
        try {
            BufferedReader reader = request.getReader();
            while ((readLen = reader.read(lineChars)) > 0) {
                for (int i = 0; i < readLen; i++) {
                    totalChars[totalLen + i] = lineChars[i];
                }
                totalLen += readLen;
            }
        } catch (Exception e) {
            log.error("数据读取错误{}", e.getMessage());
            return;
        }
}

由于参数有图片Base64数据,怀疑可能数据包过大导致tomcat服务器接不完全导致,于是增加配置参数,让Tomcat服务器不限制大小接收POST接口的数据包,默认为10M。

server.tomcat.max-http-post-size=-1

 修改后替包重启,问题得到了解决。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值