色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

解決Java中的java.io.IOException: Broken pipe問題

瀏覽:88日期:2022-08-11 10:47:21
Java 中java.io.IOException: Broken pipe認(rèn)識(shí)broken pipe

pipe是管道的意思,管道里面是數(shù)據(jù)流,通常是從文件或網(wǎng)絡(luò)套接字讀取的數(shù)據(jù)。

當(dāng)該管道從另一端突然關(guān)閉時(shí),會(huì)發(fā)生數(shù)據(jù)突然中斷,即是broken。

對于文件File來說,這可能是文件安裝在已斷開連接的光盤或遠(yuǎn)程網(wǎng)絡(luò)上。

對于socket來說,可能是網(wǎng)絡(luò)被拔出或另一端的進(jìn)程崩潰。

在Java中,沒有具體的BrokenPipeException。

將此類錯(cuò)誤包含在另一個(gè)異常,例如java.io.IOException:Broken pipe

解決問題

其實(shí)當(dāng)該異常產(chǎn)生的時(shí)候,對于服務(wù)端來說,并沒有多少影響。因?yàn)榭赡苁悄硞€(gè)客戶端突然中止了進(jìn)程導(dǎo)致了該錯(cuò)誤。但是為了程序能夠美觀、優(yōu)雅,還是要在合適的地方捕獲該異常,并處理一下。

還有一種可能性就是程序里面有代碼執(zhí)行時(shí)間過長,用戶等待時(shí)間過久,才會(huì)強(qiáng)行中止進(jìn)程。

那么這種情況下就需要去分析log中報(bào)異常的地方是經(jīng)常發(fā)生在什么地方,合理優(yōu)化該段代碼,提升代碼的運(yùn)行速度,才能從根本上避免此類問題的再次發(fā)生。

可能原因:

1、客戶端請求服務(wù)器數(shù)據(jù),服務(wù)器突然掛了;

2、客戶端請求服務(wù)端數(shù)據(jù),服務(wù)端正常返回,凡是客戶端由于超時(shí)等原因斷開。

原因分析:

做了壓力測試,發(fā)現(xiàn)遇到的情況屬于第二種,由于去數(shù)據(jù)庫取數(shù)據(jù)的時(shí)候,30秒里無法正常獲取有效的數(shù)據(jù)庫連接,或者查詢時(shí)間長,導(dǎo)致OSB過來的請求超時(shí),也就是客戶端超時(shí)了,服務(wù)端還試圖返回?cái)?shù)據(jù),結(jié)果導(dǎo)致如題異常。

解決方法:

1、增大數(shù)據(jù)庫連接池?cái)?shù)量;

2、延長客戶端超時(shí)時(shí)間。

java.io.IOException: Broken pipe 線上問題記錄

今天在上線前staging環(huán)境驗(yàn)證時(shí)遇到這樣一個(gè)問題java.io.IOException: Broken pipe,操作服務(wù)剛起來之后,測試人員第一次進(jìn)行更配[post]操作,結(jié)果操作失敗,但是第二次就好了

解決Java中的java.io.IOException: Broken pipe問題

我們是springboot+angularJs前后端分離,然后服務(wù)使用k8s在容器中部署,原始的異常棧信息是這樣,

2019-09-26T02:42:09Z [http-nio-8080-exec-9] WARN [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver:411] - Failed to invoke @ExceptionHandler method: public org.springframework.http.ResponseEntity<com.inspur.common.exception.ErrorResponse> com.inspur.common.exception.CommonControllerAdvice.exceptionHandler(javax.servlet.http.HttpServletRequest,java.lang.Exception)org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipeat org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:321)at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:284)at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:118)at org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.flush(OnCommittedResponseWrapper.java:514)at com.fasterxml.jackson.core.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1100)at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:915)at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:285)at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:102)at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:272)at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:224)at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119)at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:400)at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:61)at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)at org.springframework.web.servlet.handler.HandlerExceptionResolverComposite.resolveException(HandlerExceptionResolverComposite.java:78)at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1255)at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1062)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866)at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.inspur.common.filter.RepeatedlyReadFilter.doFilter(RepeatedlyReadFilter.java:34)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.inspur.eip.config.filter.KeyClockAuthFilter.doFilter(KeyClockAuthFilter.java:53)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.inspur.iam.adapter.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticatedActionsFilter.doFilter(KeycloakAuthenticatedActionsFilter.java:74)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.keycloak.adapters.springsecurity.filter.KeycloakSecurityContextRequestFilter.doFilter(KeycloakSecurityContextRequestFilter.java:77)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter.successfulAuthentication(KeycloakAuthenticationProcessingFilter.java:208)at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:240)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.keycloak.adapters.springsecurity.filter.KeycloakPreAuthActionsFilter.doFilter(KeycloakPreAuthActionsFilter.java:84)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)at org.springframework.security.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:155)at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:123)at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:108)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)at org.keycloak.adapters.tomcat.AbstractAuthenticatedActionsValve.invoke(AbstractAuthenticatedActionsValve.java:67)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:748)Caused by: java.io.IOException: Broken pipeat 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 org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:134)at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:101)at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:157)at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1306)at org.apache.tomcat.util.net.SocketWrapperBase.doWrite(SocketWrapperBase.java:726)at org.apache.tomcat.util.net.SocketWrapperBase.flushBlocking(SocketWrapperBase.java:679)at org.apache.tomcat.util.net.SocketWrapperBase.flush(SocketWrapperBase.java:669)at org.apache.coyote.http11.Http11OutputBuffer$SocketOutputBuffer.flush(Http11OutputBuffer.java:646)at org.apache.coyote.http11.filters.ChunkedOutputFilter.flush(ChunkedOutputFilter.java:169)at org.apache.coyote.http11.Http11OutputBuffer.flush(Http11OutputBuffer.java:252)at org.apache.coyote.http11.Http11Processor.flush(Http11Processor.java:1561)at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:380)at org.apache.coyote.Response.action(Response.java:173)at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:317)... 127 moreresolve exception

之后的操作,就正常了,正常日志如下:

解決Java中的java.io.IOException: Broken pipe問題

google之后大概知道是什么問題了

解決Java中的java.io.IOException: Broken pipe問題

注:讀懂下面這句話,首先要熟悉TCP 四次揮手,不太熟悉 請右轉(zhuǎn)google

解決Java中的java.io.IOException: Broken pipe問題

總結(jié) Broken Pipe:

這個(gè)異常是客戶端讀取超時(shí)關(guān)閉了連接,這時(shí)候服務(wù)器端再向客戶端已經(jīng)斷開的連接寫數(shù)據(jù)時(shí)就發(fā)生了broken pipe異常!

作為一個(gè)后端工程師,一定要對日常的一些異常有一個(gè)積累總結(jié),筆者就自己有在總結(jié),一是總結(jié)整理之后,下次遇到同樣的問題自己不會(huì)很茫然不知所措,尤其是在上線是,其他同事都在等著你解決問題的時(shí)候,你吭吭唧唧那就不太好了,二是筆者之前在面試時(shí)也有經(jīng)常被問到類似的問題,記憶尤新的就是被云校的百度小哥問到connection by peer,之前博客也有介紹,作為社招有經(jīng)驗(yàn)的工程師,更不能再以校招的面試作為自己的標(biāo)準(zhǔn)了,要有自己的經(jīng)驗(yàn)積累,反正就是,干,就完了

最后,附一張我的錯(cuò)誤記事本截圖

解決Java中的java.io.IOException: Broken pipe問題

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 日本午色www高清视频 | 免费看特黄特黄欧美大片 | 亚洲国产高清一区二区三区 | 国产在线播放成人免费 | 国产成人亚洲精品一区二区在线看 | 亚洲欧美日韩在线不卡中文 | 亚洲伦 | 亚欧精品在线观看 | 婷婷尹人香蕉久久天堂 | a级一级黄色片 | 日韩在线小视频 | 香蕉久久精品 | 亚洲一区免费看 | 91精品国产福利尤物免费 | 亚洲国产精品第一区二区三区 | 日韩欧美在线视频一区二区 | 热99re久久国超精品首页 | 久久精品免视看国产明星 | 国产21区| 亚洲成人高清 | 欧美aaa| 国产精品麻豆一区二区三区v视界 | 国产偷国产偷亚洲高清午夜 | 欧美精品日本一级特黄 | 欧美成人高清 | 日韩欧美高清在线观看 | 国产高清成人mv在线观看 | caoporen免费公开视频上传 | 亚洲男人的天堂成人 | 全国男人的天堂天堂网 | 91伦理视频 | 欧美日韩亚洲综合久久久 | 99久久免费看精品国产一区 | 美女视频黄a视频免费全程 美女视频黄a视频免费全过程 | 韩国一级特黄清高免费大片 | 毛片视频在线免费观看 | 久久国产精品久久久久久久久久 | 中文字幕视频网 | 国产网站黄色 | 美女黄视频免费观看 | 亚洲精品自拍视频 |