Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] session.sendText(str, Callback.from(session::demand, Throwable::printStackTrace)) in a loop results in java.nio.channels.ReadPendingException
  • From: Alexander Farber <farber72@xxxxxxxxxx>
  • Date: Fri, 8 Nov 2024 10:29:00 +0000
  • Accept-language: en-US, de-DE
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IvxOK+QVA/9QM33m87FCLZHxlneYjAf0oFdjYIjmWms=; b=vTudq2EkUcBoKaEyx4XXrExu2Px1j8ocKCdD0rUNZXudTvtejvm7ZpomRrSMcDAWz8mYwYAGKFGhxD0o3Cr/XQ+/OI/grMH6L4NjWJgJAeT3V55/0lZsRVcp7FzOj2eziCnbi+uAgu6pjrwzKCYHxoy+/1tArus8Tx3H8T/i+kuL84w6C71juSbrd1LWXiNKj+4MhLggEH6aoYCYSGdWkuSrzyGRkQJV5X1w5/iOyuF8mL2VpjmpjT2gZwUrKE2cv1AsoDQGY4AKnCM8SpR6C1e/zQgYo+NEt5lHSb6WgUynyPqoEDhvDtMsTp2PcelxyC/uvNBy2l2rMoaOS/Nfew==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KxF7dXCu7b9Ve65Au1uvshqXDdJRSP9SecqT9mDOvVwTRJL3BKrYkHklQ21lJjyCZMG41h6w+w4TjrB4SK9AKny4+MDDqa3aM0BeOVQBNABxiaHHgzHQOW1p3wfZC5FjjnBbLRFRtyfXEc86qaEPiQUu4Jt1eb25hUhHZOoGmJ1rMneeRCFfn5Esf8sgL9zK5Bu/dhM2/ywpPIoHzT4bChf/dvTc2U9UaSIbvOJkS9NRz0rt1RZNsRjPaipbPuaa2rt/HKGOSHPivk9/rZlFvOgKJ9Fuaz9E0mpj6T605e4pgCQD9mGKJ2r9YHcFMyPj0NR1drPw4uEIpanD2wOQ3Q==
  • Delivered-to: jetty-users@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jetty-users/>
  • List-help: <mailto:jetty-users-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jetty-users>, <mailto:jetty-users-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jetty-users>, <mailto:jetty-users-request@eclipse.org?subject=unsubscribe>
  • Msip_labels:
  • Thread-index: AQHbMceOfajvrdt6/Ee0swYfVGBzvA==
  • Thread-topic: session.sendText(str, Callback.from(session::demand, Throwable::printStackTrace)) in a loop results in java.nio.channels.ReadPendingException

Hello,

I am migrating a Websockets game from Jetty 10 to Jetty 12 with no auto-demand 
and have replaced org.eclipse.jetty.websocket.api.Callback.NOOP by the new callback 
in code below, so that I can call the "demand()" method:

    // the method below is called by the public void onWebSocketText(String str)

    private void handleNewGame() throws SQLException, IOException {
           // here some PostgreSQL code

            String gidJsonStr = String.format("{\"gid\":%d}", gid);
            // a new game has been created, get the new games list
            String gamesJsonStr = mServlet.getGames(mUid);

            for (Session session : Client.getOpenSessions(mUid)) {
                // send updated games list to all open sessions of this user
                session.sendText(gamesJsonStr, Callback.from(session::demand, Throwable::printStackTrace));
                // send the new game id to all open sessions of this user
                session.sendText(gidJsonStr, Callback.from(session::demand, Throwable::printStackTrace));
            }

I.e. if a user is playing the game in several browser tabs, I would like to 
send the up-to-date list of games (gamesJsonStr) to the user's every 
connected Websocket client (to his/here every browser tab).

However I get the exception:

2024-11-08 11:13:58.492:WARN :oejwc.WebSocketCoreSession$Flusher:qtp183284570-53: Exception while notifying success of callback Callback@2792df7d{BLOCKING, org.eclipse.jetty.websocket.common.WebSocketSession$$Lambda/0x000001da8131e8e0@68c25a59,org.eclipse.jetty.websocket.common.WebSocketSession$$Lambda/0x000001da8131eb00@25efa676}
java.nio.channels.ReadPendingException
        at org.eclipse.jetty.websocket.core.util.DemandingFlusher.demand(DemandingFlusher.java:82)
        at org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension.demand(PerMessageDeflateExtension.java:262)
        at org.eclipse.jetty.websocket.core.ExtensionStack.demand(ExtensionStack.java:276)
        at org.eclipse.jetty.websocket.core.WebSocketCoreSession.demand(WebSocketCoreSession.java:416)
        at org.eclipse.jetty.websocket.common.WebSocketSession.demand(WebSocketSession.java:58)
        at org.eclipse.jetty.websocket.api.Callback$2.succeed(Callback.java:49)
        at org.eclipse.jetty.util.Callback$3.succeeded(Callback.java:170)
        at org.eclipse.jetty.websocket.core.util.TransformingFlusher.notifyCallbackSuccess(TransformingFlusher.java:195)
        at org.eclipse.jetty.websocket.core.util.TransformingFlusher$Flusher.process(TransformingFlusher.java:152)
        at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:262)
        at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:243)
        at org.eclipse.jetty.websocket.core.util.TransformingFlusher.sendFrame(TransformingFlusher.java:78)
        at org.eclipse.jetty.websocket.core.WebSocketCoreSession.sendFrame(WebSocketCoreSession.java:508)
        at org.eclipse.jetty.websocket.common.WebSocketSession.sendText(WebSocketSession.java:108)
        at de.afarber.WordsListener.handleLogin(WordsListener.java:210)
        at de.afarber.WordsListener.onWebSocketText(WordsListener.java:105)
        at org.eclipse.jetty.websocket.core.messages.StringMessageSink.accept(StringMessageSink.java:67)
        at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.acceptFrame(JettyWebSocketFrameHandler.java:397)
        at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.onTextFrame(JettyWebSocketFrameHandler.java:368)
        at org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.onFrame(JettyWebSocketFrameHandler.java:216)
        at org.eclipse.jetty.websocket.core.WebSocketCoreSession$IncomingAdaptor.lambda$onFrame$0(WebSocketCoreSession.java:647)
        at org.eclipse.jetty.server.handler.ContextHandler$ScopedContext.run(ContextHandler.java:1513)
        at org.eclipse.jetty.server.handler.ContextHandler$ScopedContext.run(ContextHandler.java:1500)
        at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker$1.handle(AbstractHandshaker.java:179)
        at org.eclipse.jetty.websocket.core.WebSocketCoreSession$IncomingAdaptor.onFrame(WebSocketCoreSession.java:647)
        at org.eclipse.jetty.websocket.core.AbstractExtension.nextIncomingFrame(AbstractExtension.java:145)
        at org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension.nextIncomingFrame(PerMessageDeflateExtension.java:239)
        at org.eclipse.jetty.websocket.core.util.DemandingFlusher.emitFrame(DemandingFlusher.java:143)
        at org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension$IncomingFlusher.inflate(PerMessageDeflateExtension.java:492)
        at org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension$IncomingFlusher.handle(PerMessageDeflateExtension.java:417)
        at org.eclipse.jetty.websocket.core.util.DemandingFlusher.process(DemandingFlusher.java:167)
        at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:262)
        at org.eclipse.jetty.util.IteratingCallback.succeeded(IteratingCallback.java:403)
        at org.eclipse.jetty.websocket.core.util.DemandingFlusher.onFrame(DemandingFlusher.java:105)
        at org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension.onFrame(PerMessageDeflateExtension.java:96)
        at org.eclipse.jetty.websocket.core.ExtensionStack.onFrame(ExtensionStack.java:113)
        at org.eclipse.jetty.websocket.core.WebSocketCoreSession.onFrame(WebSocketCoreSession.java:463)
        at org.eclipse.jetty.websocket.core.WebSocketConnection.onFrame(WebSocketConnection.java:254)
        at org.eclipse.jetty.websocket.core.WebSocketConnection.fillAndParse(WebSocketConnection.java:447)
        at org.eclipse.jetty.websocket.core.WebSocketConnection.onFillable(WebSocketConnection.java:332)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
        at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
        at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:478)
        at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:441)
        at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)
        at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
        at java.base/java.lang.Thread.run(Thread.java:1583)

I think Jetty wanted to call the callback lambda to tell 
that everything is good ("... notifyCallbackSuccess ..."), but fails.

Why does it fail, could you please give me some hints?

Is it because I loop and the "Session session" variable goes out of scope? 
Or something else? And how to call the "demand()" then?

Best regards
Alex

Back to the top