Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket: java.lang.IllegalStateException: already released RetainableByteBuffer #7086

Closed
leonchen83 opened this issue Nov 8, 2021 · 3 comments · Fixed by #7088
Closed
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@leonchen83
Copy link
Contributor

leonchen83 commented Nov 8, 2021

Jetty version(s)
10.0.7
Java version/vendor (use: java -version)
openjdk 11
OS type/version
Linux version 2.6.32-642.el6.x86_64 (mockbuild@worker1.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ) #1 SMP Tue May 10 17:27:01 UTC 2016
Description
occur exception on our prod env

AdaptiveExecutionStrategy.runTask:416]Task run failed
java.lang.IllegalStateException: already released RetainableByteBuffer@2c03deb4{DirectByteBuffer@6bbc693a[p=0,l=0,c=4096,r=0]={<<<>>>??ÖW?{i...},r=0}
at org.eclipse.jetty.io.RetainableByteBuffer.lambdarelease2(RetainableByteBuffer.java:109)
at java.base/java.util.concurrent.atomic.AtomicInteger.updateAndGet(AtomicInteger.java:279)
at org.eclipse.jetty.io.RetainableByteBuffer.release(RetainableByteBuffer.java:106)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.releaseNetworkBuffer(WebSocketConnection.java:333)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.fillAndParse(WebSocketConnection.java:507)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.onFillable(WebSocketConnection.java:343)
at org.eclipse.jetty.io.AbstractConnectionReadCallback.succeeded(AbstractConnection.java:319)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.SocketChannelEndPoint1.run(SocketChannelEndPoint.java:101)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:412)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:381)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:268)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambdanew0(AdaptiveExecutionStrategy.java:138)
at org.eclipse.jetty.util.thread.ReservedThreadExecutorReservedThread.run(ReservedThreadExecutor.java:407)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
at org.eclipse.jetty.util.thread.QueuedThreadPoolRunner.run(QueuedThreadPool.java:1038)
at java.base/java.lang.Thread.run(Thread.java:834)

Do not report security issues here! See Jetty Security Reports.

How to reproduce?

it`s hard to reproduce

@leonchen83 leonchen83 added the Bug For general bugs on Jetty side label Nov 8, 2021
@lachlan-roberts
Copy link
Contributor

There is not enough information to tell why this is happening.

@leonchen83 are you using the Jetty API or the Javax WebSocket API? and what type of message handler are you using for this websocket connection?

@lachlan-roberts lachlan-roberts self-assigned this Nov 8, 2021
@leonchen83
Copy link
Contributor Author

we extend spring WebSocketHandler and handle text message with client
code like following

public class XWebSocketHandler implements WebSocketHandler {
....
....
    public final void handleMessage(final WebSocketSession session, final WebSocketMessage<?> message) throws Exception {
        if (message instanceof TextMessage) {
            // do our buinesses

        }
    }
}

lachlan-roberts added a commit that referenced this issue Nov 8, 2021
…sed.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Nov 9, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@lachlan-roberts
Copy link
Contributor

I think I've figured out why this is happening.

The WebSocketCoreSession.demand() method will throw ISE if the session is no longer open. And this is typically done in a format like this:

try
{
  ...
  callback.succeeded();
  coreSession.demand(1);
}
catch(Throwable t)
{
  callback.failed(t);
}

So if demand throws because the session is closed then it is both succeeding and failing the callback. You can trigger this by sending an error close frame from the onMessage method. See fix in PR #7088.

@joakime joakime added this to To do in Jetty 10.0.8/11.0.8 - FROZEN via automation Nov 9, 2021
@joakime joakime moved this from To do to Review in progress in Jetty 10.0.8/11.0.8 - FROZEN Nov 9, 2021
lachlan-roberts added a commit that referenced this issue Nov 9, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@joakime joakime moved this from Review in progress to In progress in Jetty 10.0.8/11.0.8 - FROZEN Nov 15, 2021
Jetty 10.0.8/11.0.8 - FROZEN automation moved this from In progress to Done Nov 16, 2021
lachlan-roberts added a commit that referenced this issue Nov 16, 2021
…ageSinks

Issue #7086 - fix issues when calling websocket demand
@joakime joakime changed the title java.lang.IllegalStateException: already released WebSocket: java.lang.IllegalStateException: already released RetainableByteBuffer Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants