java.io.IOException: java.util.concurrent.ExecutionException: java.net.SocketException: Software cau

在用websocket时,由于直接关闭浏览器导致后台报错如下:

java.io.IOException: java.util.concurrent.ExecutionException: java.net.SocketException: Software caused connection abort: socket write error
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:230) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:477) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsSession.onClose(WsSession.java:440) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsFrameBase.processDataControl(WsFrameBase.java:316) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:270) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:116) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:54) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:192) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:178) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:92) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:601) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
Caused by: java.util.concurrent.ExecutionException: java.net.SocketException: Software caused connection abort: socket write error
    at org.apache.tomcat.websocket.FutureToSendHandler.get(FutureToSendHandler.java:102) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:225) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    ... 14 common frames omitted
Caused by: java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_91]
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_91]
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_91]
    at org.apache.coyote.http11.upgrade.BioServletOutputStream.doWrite(BioServletOutputStream.java:37) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.http11.upgrade.AbstractServletOutputStream.writeInternal(AbstractServletOutputStream.java:123) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.http11.upgrade.AbstractServletOutputStream.write(AbstractServletOutputStream.java:90) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer.onWritePossible(WsRemoteEndpointImplServer.java:84) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer.doWrite(WsRemoteEndpointImplServer.java:71) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:368) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:265) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:220) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    ... 14 common frames omitted
09:47:42.530 [http-bio-8080-exec-1] DEBUG o.s.w.s.a.NativeWebSocketSession - Closing StandardWebSocketSession[id=1, uri=/ArthasMenethil/webSocketServer]
09:47:42.531 [http-bio-8080-exec-1] DEBUG o.s.w.s.h.ExceptionWebSocketHandlerDecorator - Closing due to exception for StandardWebSocketSession[id=1, uri=/ArthasMenethil/webSocketServer]
java.lang.IllegalStateException: Message will not be sent because the WebSocket session has been closed
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:302) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:265) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:220) ~[tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:477) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsSession.doClose(WsSession.java:417) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsSession.close(WsSession.java:394) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.closeInternal(StandardWebSocketSession.java:217) ~[spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.web.socket.adapter.AbstractWebSocketSession.close(AbstractWebSocketSession.java:139) ~[spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.web.socket.adapter.AbstractWebSocketSession.close(AbstractWebSocketSession.java:130) ~[spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at com.websocket.WebsocketHandler.handleTransportError(WebsocketHandler.java:114) ~[classes/:na]
    at org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleTransportError(WebSocketHandlerDecorator.java:80) ~[spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.handleTransportError(LoggingWebSocketHandlerDecorator.java:64) ~[spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.handleTransportError(ExceptionWebSocketHandlerDecorator.java:68) ~[spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.onError(StandardWebSocketHandlerAdapter.java:153) [spring-websocket-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:491) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsSession.onClose(WsSession.java:440) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsFrameBase.processDataControl(WsFrameBase.java:316) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:270) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:116) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:54) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:192) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:178) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:92) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:601) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) [tomcat-embed-core-7.0.47.jar:7.0.47]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

这是由于在直接关闭浏览器之前没有关闭websocket导致的,所以要记得正确关闭websocket,在关闭浏览器之前 
解决:

window.onbeforeunload = function(event) { 
    WS.onclose =function(){};
    WS.close();
}

你可能感兴趣的:(webSocket)