当多个连接打开时SockJS连接将被关闭
如果仅打开一个 SockJS(轮询 XHR)连接,则该应用程序可以正常工作。一旦我在新窗口中打开它,连接就会定期关闭。客户端是SockJS客户端,后端是启用了MVC和SockJS的Spring Boot。
这是我在服务器端看到的:
2022-03-14 10:40:20.992 DEBUG 752 --- [nio-8311-exec-7] a.w.b.u.d.websocket.WebSocketHandler : connection opened, id: gqgmlrff
2022-03-14 10:40:21.015 DEBUG 752 --- [nio-8311-exec-9] a.w.b.u.d.websocket.WebSocketHandler : Server received message: {"action":"subscribe","payload":{"id":"c910f5d1-9e16-4e30-9559-e0e27973177b","entityType":"PROJEKT"}}
15-20 秒后
2022-03-14 10:40:40.075 DEBUG 752 --- [ SockJS-10] a.w.b.u.d.websocket.WebSocketHandler : connection closed, sessionId: gqgmlrff, status: CloseStatus[code=3000, reason=Go away!]
这会在两个窗口的会话中无限重复。 会话关闭似乎将由后端启动,因为在客户端将执行 .onclose()
处理程序。
If only one SockJS (polling XHR) connection is open, then the app works fine. As soon as I additionally open it in a new window, then the connections will periodically be closed. The client is SockJS client, the backend is Spring Boot with MVC and SockJS enabled.
This is what I see on the server side:
2022-03-14 10:40:20.992 DEBUG 752 --- [nio-8311-exec-7] a.w.b.u.d.websocket.WebSocketHandler : connection opened, id: gqgmlrff
2022-03-14 10:40:21.015 DEBUG 752 --- [nio-8311-exec-9] a.w.b.u.d.websocket.WebSocketHandler : Server received message: {"action":"subscribe","payload":{"id":"c910f5d1-9e16-4e30-9559-e0e27973177b","entityType":"PROJEKT"}}
after 15-20 seconds
2022-03-14 10:40:40.075 DEBUG 752 --- [ SockJS-10] a.w.b.u.d.websocket.WebSocketHandler : connection closed, sessionId: gqgmlrff, status: CloseStatus[code=3000, reason=Go away!]
This repeats infinitely with sessions of both windows.
It seems that the session closing will be initiated by the backend, since on client side the .onclose()
handler will be executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是,对于两个应用程序实例,都生成了不同的身份验证令牌,并且相等性未更新。如下更新
equals()
和 hashCode() 后,请求已正确处理。The reason was that for both app instances different auth tokens have been generated and the equality wasn't updated. After updating
equals()
and hashCode() as follow the requests were correctly processed.