使用WebSocket做APP的通知服务,但是批量推送的时候报错:The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
2021/08/05 09:45:34.364 INFO [task-33261] Base : ===> 收到消息转发给APP(userId=107):{“messageId”:”c73f2e6f-3c36-48a6-91ae-a59854aa992e”}
2021/08/05 09:45:34.365 INFO [task-33261] Base : 发送数据 -> 开始
2021/08/05 09:45:34.389 ERROR [task-33261] o.s.a.i.SimpleAsyncUncaughtExceptionHandler : Unexpected exception occurred invoking async method: public void com.ikonke.ws.system.bus.EventSenderListener.onApplicationEvent(com.ikonke.ws.system.bus.event.EventSender)
java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1258) ~[tomcat-embed-websocket-9.0.41.jar!/:9.0.41]
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.textStart(WsRemoteEndpointImplBase.java:1220) ~[tomcat-embed-websocket-9.0.41.jar!/:9.0.41]
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendString(WsRemoteEndpointImplBase.java:191) ~[tomcat-embed-websocket-9.0.41.jar!/:9.0.41]
at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:37) ~[tomcat-embed-websocket-9.0.41.jar!/:9.0.41]
at com.ikonke.ws.socket.WSHandler.sendMessage(WSHandler.java:104) ~[classes!/:0.0.1-SNAPSHOT]
at com.ikonke.ws.system.bus.EventSenderListener.onApplicationEvent(EventSenderListener.java:69) ~[classes!/:0.0.1-SNAPSHOT]
at com.ikonke.ws.system.bus.EventSenderListener.onApplicationEvent(EventSenderListener.java:25) ~[classes!/:0.0.1-SNAPSHOT]
at com.ikonke.ws.system.bus.EventSenderListener$$FastClassBySpringCGLIB$$a5414582.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.cloud.sleuth.instrument.async.TraceAsyncAspect.traceBackgroundThread(TraceAsyncAspect.java:70) ~[spring-cloud-sleuth-core-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_171]
at org.springframework.cloud.sleuth.instrument.async.TraceRunnable.run(TraceRunnable.java:68) ~[spring-cloud-sleuth-core-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
at org.springframework.cloud.sleuth.instrument.async.TraceRunnable.run(TraceRunnable.java:68) ~[spring-cloud-sleuth-core-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
TEXT_FULL_WRITING的状态是当前会话正在输出数据,那么需要将send的方法改为同步,如下:
public synchronized void sendMessage(Session session, String message) { try { logger("发送数据 -> 开始"); session.getBasicRemote().sendText(message); logger("发送数据 -> 成功"); } catch (IOException e) { e.printStackTrace(); } }
近期评论