gpt4 book ai didi

java - 服务器端处理丢失的客户端连接(由对等方重置)?

转载 作者:行者123 更新时间:2023-12-01 05:05:50 25 4
gpt4 key购买 nike

我有一个网络服务和一个客户端。有时客户端连接后,并没有立即获得返回值。稍后,如果从 WS 返回一个值并且客户端同时关闭,我会收到不知道如何处理的异常。

我怎样才能捕获那些由对等方重置的异常,以便网络服务器不会崩溃?

@Webservice
class MyWebservice {
public boolean myWebserviceMethod() {
//sleep, cut the client, then return.
return false;
}
}

2012 年 10 月 2 日 2:26:52 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging

Warnung: Interceptor for {http://myproject.de/wsdl}ConnectionService#{http://myproject.de/wsdl}myWebserviceMethod has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
at org.apache.openejb.server.cxf.CxfWsContainer.onMessage(CxfWsContainer.java:73)
at org.apache.openejb.server.webservices.WsServlet.service(WsServlet.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:346)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:306)
at org.apache.catalina.connector.Response.flushBuffer(Response.java:568)
at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:307)
at org.apache.openejb.server.httpd.ServletResponseAdapter.flushBuffer(ServletResponseAdapter.java:205)
at org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.close(AbstractHTTPDestination.java:684)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.AbstractHTTPDestination$BackChannelConduit.close(AbstractHTTPDestination.java:626)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
... 24 more
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:215)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:462)
at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:119)
at org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:789)
at org.apache.coyote.Response.action(Response.java:174)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:341)
... 32 more

最佳答案

服务器确实崩溃了,还是您通过查看堆栈跟踪(错误地)得出服务器崩溃的结论?

之所以存在堆栈跟踪,是因为 Catalina 无法向为与客户端通信而打开的套接字写入响应。这种异常在这种情况下总会出现; Catalina 无法确切知道为什么它无法写入套接字 - 它只知道它无法写入响应。它打印堆栈跟踪(因为这是一个错误条件,可能对系统管理员有值(value),例如用于性能调整目的),然后继续。

如果一旦出现这种情况,您的服务器确实崩溃了,那么您可能会遇到更大的问题。我发现很难相信如果服务器无法向死掉的 TCP/IP 套接字写入响应,它实际上会崩溃。

关于java - 服务器端处理丢失的客户端连接(由对等方重置)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12690366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com