无法将jetty websocket maxidletimeout设置为60秒以上

hiz5n14c  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(689)

我正在尝试使用jettywebsockets,并希望为连接的会话设置一个用户可配置的空闲超时设置。似乎所有尝试都会导致60秒的超时:

org.eclipse.jetty.websocket.api.CloseException: java.util.concurrent.TimeoutException: Idle timeout expired: 60002/60000 ms
        at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onReadTimeout(AbstractWebSocketConnection.java:567)
        at org.eclipse.jetty.io.AbstractConnection.onFillInterestedFailed(AbstractConnection.java:172)
        at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillInterestedFailed(AbstractWebSocketConnection.java:540)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.failed(AbstractConnection.java:317)
        at org.eclipse.jetty.io.FillInterest.onFail(FillInterest.java:138)
        at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillableFail(SslConnection.java:579)
        at org.eclipse.jetty.io.ssl.SslConnection.onFillInterestedFailed(SslConnection.java:407)
        at org.eclipse.jetty.io.ssl.SslConnection$2.failed(SslConnection.java:167)
        at org.eclipse.jetty.io.FillInterest.onFail(FillInterest.java:138)
        at org.eclipse.jetty.io.AbstractEndPoint.onIdleExpired(AbstractEndPoint.java:407)
        at org.eclipse.jetty.io.IdleTimeout.checkIdleTimeout(IdleTimeout.java:171)
        at org.eclipse.jetty.io.IdleTimeout.idleCheck(IdleTimeout.java:113)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)

对每个ws会话使用jetty9.4.26和@websocket注解的pojo。
在注解中设置一个值实际上是不可行的,因为空闲超时需要在运行时进行配置。但是,即使设置为60秒以下,也只会产生影响:

@WebSocket(maxIdleTime = 65000) \\Idle timeout expired: 60002/60000 ms
@WebSocket(maxIdleTime = 50000) \\Idle timeout expired: 50001/50000 ms

如果我手动设置传入@onwebsocketconnect方法的会话超时,则完全相同:

session.setIdleTimeout(65000); \\Idle timeout expired: 60001/60000 ms
session.setIdleTimeout(50000); \\Idle timeout expired: 50001/50000 ms

在websocketclient上调用connect(),我将其示例化为singleton,并将带注解的pojo传递到connect():

HttpClient jettyHttpClient = new HttpClient(getWebSocketSslContextFactory());
jettyHttpClient.start();
WebSocketClient wsClient = new WebSocketClient(jettyHttpClient);
wsClient.start();

但是,如果使用以下任一项,则上述超时行为仍然相同:

wsClient.getPolicy().setIdleTimeout(65000);
wsClient.setMaxIdleTimeout(65000);

jettyhttpclient.setidletimeout();似乎一点影响都没有。。。。
在idletimeout的setidletimeout()中添加断点并不能使事情变得更清楚,在连接过程中,该断点在4个不同的示例上被命中6次:

0       set in SocketChannelEndpoint (instance 1)   via  ClientSelectorManager.newEndPoint
300000  set in SocketChannelEndpoint (instance 2)   via  ServerConnector.newEndPoint
-1      set in SslConnection$DecyptedEndPoint (instance 1) via Constructor
-1      set in SslConnection$DecyptedEndPoint (instance 2) via setIdleTimeout
60000   set in SocketChannelEndpoint (instance 2)  via  WebSocketServerFactory.upgrade
65000   set in SocketChannelEndpoint (instance 1)  via  WebSocketUpgradeRequest.upgrade

我基本上不知道内部发生了什么。有5种设置超时的方法,似乎没有什么工作超过60秒。
类似于此线程的请求,但没有足够的代表在那里发表评论,因此出现了新线程。码头腹板箱空转时间

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题