解决Java中的java.io.IOException:Brokenpipe问题

更新时间:2023-07-13 12:16:12 阅读: 评论:0

解决Java中的java.io.IOException:Brokenpipe问题
Java 中java.io.IOException: Broken pipe
认识broken pipe
pipe是管道的意思,管道⾥⾯是数据流,通常是从⽂件或⽹络套接字读取的数据。
当该管道从另⼀端突然关闭时,会发⽣数据突然中断,即是broken。
对于⽂件File来说,这可能是⽂件安装在已断开连接的光盘或远程⽹络上。
对于socket来说,可能是⽹络被拔出或另⼀端的进程崩溃。
在Java中,没有具体的BrokenPipeException。
将此类错误包含在另⼀个异常,例如java.io.IOException:Broken pipe
解决问题
其实当该异常产⽣的时候,对于服务端来说,并没有多少影响。因为可能是某个客户端突然中⽌了进程导致了该错误。但是为了程序能够美观、优雅,还是要在合适的地⽅捕获该异常,并处理⼀下。
还有⼀种可能性就是程序⾥⾯有代码执⾏时间过长,⽤户等待时间过久,才会强⾏中⽌进程。
无形资产减值准备
那么这种情况下就需要去分析log中报异常的地⽅是经常发⽣在什么地⽅,合理优化该段代码,提升代码的运⾏速度,才能从根本上避免此类问题的再次发⽣。
可能原因:
1、客户端请求服务器数据,服务器突然挂了;
2、客户端请求服务端数据,服务端正常返回,凡是客户端由于超时等原因断开。
原因分析:
做了压⼒测试,发现遇到的情况属于第⼆种,由于去数据库取数据的时候,30秒⾥⽆法正常获取有效的数据库连接,或者查询时间长,导致OSB过来的请求超时,也就是客户端超时了,服务端还试图返
回数据,结果导致如题异常。
解决⽅法:
甜酒的制作过程
1、增⼤数据库连接池数量;
2、延长客户端超时时间。
java.io.IOException: Broken pipe 线上问题记录
肯德基代言人今天在上线前staging环境验证时遇到这样⼀个问题java.io.IOException: Broken pipe,操作服务刚起来之后,测试⼈员第⼀次进⾏更配[post]操作,结果操作失败,但是第⼆次就好了,
我们是springboot+angularJs前后端分离,然后服务使⽤k8s在容器中部署,原始的异常栈信息是这样,
2019-09-26T02:42:09Z [http-nio-8080-exec-9] WARN  [org.springframework.web.hod.annotation.ExceptionHandlerExceptionResolver:411] -
Failed to invoke @ExceptionHandler method: public org.springframework.http.ResponEntity<com.inspu org.tor.ClientAbortException: java.io.IOException: Broken pipe
at org.tor.OutputBuffer.doFlush(OutputBuffer.java:321)
at org.tor.OutputBuffer.flush(OutputBuffer.java:284)
at org.tor.CoyoteOutputStream.flush(CoyoteOutputStream.java:118)
at org.springframework.curity.web.util.OnCommittedResponWrapper$SaveContextServletOutputStream.flush(OnCommittedResponWrapper.java:514)
at com.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1100)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:915)
at org.verter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:285)
at org.verter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:102)
at org.springframework.web.hod.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:272)
at org.springframework.web.hod.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:224)
at org.hod.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82)
at org.springframework.web.hod.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119)
at org.springframework.web.hod.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:400)
at org.springframework.web.rvlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:61)
at org.springframework.web.rvlet.solveException(AbstractHandlerExceptionResolver.java:136)
at org.springframework.web.rvlet.solveException(HandlerExceptionResolverComposite.java:78)
at org.springframework.web.rvlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1255)
at org.springframework.web.rvlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1062)
at org.springframework.web.rvlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)
at org.springframework.web.rvlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.rvlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
at org.springframework.web.rvlet.FrameworkServlet.doGet(FrameworkServlet.java:866)
at javax.rvlet.http.HttpServlet.rvice(HttpServlet.java:687)
at org.springframework.web.rvlet.FrameworkServlet.rvice(FrameworkServlet.java:851)
at javax.rvlet.http.HttpServlet.rvice(HttpServlet.java:790)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at at.websocket.rver.WsFilter.doFilter(WsFilter.java:52)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at filter.RepeatedlyReadFilter.doFilter(RepeatedlyReadFilter.java:34)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.fig.filter.KeyClockAuthFilter.doFilter(KeyClockAuthFilter.java:53)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.ace.rvlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.inspur.iam.adapter.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:119)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.curity.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.curity.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.ssion.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.keycloak.adapters.springcurity.filter.KeycloakAuthenticatedActionsFilter.doFilter(KeycloakAuthenticatedActionsFilter.java:74)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.keycloak.adapters.springcurity.filter.KeycloakSecurityContextRequestFilter.doFilter(KeycloakSecurityContextRequestFilter.java:77)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.rvletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.keycloak.adapters.springcurity.filter.KeycloakAuthenticationProcessingFilter.successfulAuthentication(KeycloakAuthenticationProcessingFilter.java:208) at org.springframework.curity.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:240)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
天方奇迹
对峙拼音at org.springframework.curity.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.keycloak.adapters.springcurity.filter.KeycloakPreAuthActionsFilter.doFilter(KeycloakPreAuthActionsFilter.java:84)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.ja
va:66)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.t.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.t.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.curity.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.curity.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.curity.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
北寺塔at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.ics.web.rvlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:155)
at org.springframework.ics.web.rvlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:123)
at org.springframework.ics.web.rvlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:108)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
免费网站视频at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.StandardContextValve.invoke(StandardContextValve.java:96)
at org.at.AbstractAuthenticatedActionsValve.invoke(AbstractAuthenticatedActionsValve.java:67)
at org.apache.catalina.authenticator.AuthenticatorBa.invoke(AuthenticatorBa.java:493)
at org.at.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181)
at org.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.tor.CoyoteAdapter.rvice(CoyoteAdapter.java:342)
at http11.Http11Processor.rvice(Http11Processor.java:800)
at AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at at.util.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at at.util.SocketProcessorBa.run(SocketProcessorBa.java:49)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at at.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caud by: java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:65)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
at at.util.NioChannel.write(NioChannel.java:134)
at at.util.NioBlockingSelector.write(NioBlockingSelector.java:101)
at at.util.NioSelectorPool.write(NioSelectorPool.java:157)
at at.util.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1306)
at at.util.SocketWrapperBa.doWrite(SocketWrapperBa.java:726)
at at.util.SocketWrapperBa.flushBlocking(SocketWrapperBa.java:679)
at at.util.SocketWrapperBa.flush(SocketWrapperBa.java:669)
at http11.Http11OutputBuffer$SocketOutputBuffer.flush(Http11OutputBuffer.java:646)
at http11.filters.ChunkedOutputFilter.flush(ChunkedOutputFilter.java:169)
at http11.Http11OutputBuffer.flush(Http11OutputBuffer.java:252)
at http11.Http11Processor.flush(Http11Processor.java:1561)
at AbstractProcessor.action(AbstractProcessor.java:380)
at Respon.action(Respon.java:173)
at org.tor.OutputBuffer.doFlush(OutputBuffer.java:317)
... 127 more
resolve exception
之后的操作,就正常了,正常⽇志如下:
夜深了
google之后⼤概知道是什么问题了
注:读懂下⾯这句话,⾸先要熟悉TCP 四次挥⼿,不太熟悉请右转google
总结 Broken Pipe:
这个异常是客户端读取超时关闭了连接,这时候服务器端再向客户端已经断开的连接写数据时就发⽣了broken pipe异常!
作为⼀个后端⼯程师,⼀定要对⽇常的⼀些异常有⼀个积累总结,笔者就⾃⼰有在总结,⼀是总结整理之后,下次遇到同样的问题⾃⼰不会很茫然不知所措,尤其是在上线是,其他同事都在等着你解决问题的时候,你吭吭唧唧那就不太好了,⼆是笔者之前在⾯试时也有经常被问到类似的问题,记忆尤新的就是被云校的百度⼩哥问到connection by peer,之前博客也有介绍,作为社招有经验的⼯程师,更不能再以校招的⾯试作为⾃⼰的标准了,要有⾃⼰的经验积累,反正就是,⼲,就完了
最后,附⼀张我的错误记事本截图
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

本文发布于:2023-07-13 12:16:12,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1094288.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数据   客户端   问题   代码   遇到   服务端   连接   错误
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图