Skip to content

AssertionError at WebSocketImpl.isOpen #694

Closed

Description

@PhilipRoman

Expected Behavior

WebSocketImpl.isOpen() returns true if the socket is open and false otherwise.

Current Behavior

Calling isOpen() on a websocket causes and AssertionError. Here is the assertion causing it:
assert ( getReadyState() != READYSTATE.OPEN || !flushandclosestate )
It is not entirely clear why such a method would ever throw an exception. There are 2 possible stacktraces which appear randomly:

Exception in thread "WebSocketSelector-15" java.lang.AssertionError
	at org.java_websocket.WebSocketImpl.isOpen(WebSocketImpl.java:720)
	at com.mypackage.ClientConnection.send(ClientConnection.java:130)
	[Bussiness logic frames here...]
	at com.mypackage.Cluster.onClose(Cluster.java:114)
	at org.java_websocket.server.WebSocketServer.onWebsocketClose(WebSocketServer.java:595)
	at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:504)
	at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:522)
	at org.java_websocket.SocketChannelIOHelper.batch(SocketChannelIOHelper.java:99)
	at org.java_websocket.server.WebSocketServer.run(WebSocketServer.java:428)
	at java.base/java.lang.Thread.run(Thread.java:844)
Uncaught exception in thread "WebSocketWorker-14":java.lang.AssertionError
	at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:225)
	at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:906)

Steps to Reproduce (for bugs)

I'll make a minimal program to reproduce it and other info unless it turns out to be a mistake from my own code. The bug is hard to reproduce reliably.
Here is a brief outline of how I get the bug:

final Cluster cluster = new Cluster(20); // subclass of WebSocketServer
final int clientCount = 20;
Executor executor = Executors.newCachedThreadPool();
cluster.start();
for (int i = 0; i < 10; i++) {
	int port = cluster.getPort();
	Collection<MockClient> clients = Stream.generate(() -> new MockClient(port))
		.limit(clientCount)
		.collect(Collectors.toCollection(() -> new ArrayList<>(clientCount)));
	clients.forEach(executor::execute);
	sleep(2000);
	clients.forEach(WebSocketClient::close);
	sleep(2000);
}

Activity

  1. added this to the Release 1.3.9 milestone on Apr 16, 2018
  2. marci4 commented on Apr 16, 2018

    @marci4
    Collaborator

    Hello @PhilipRoman,

    thank you very much for your bug report!

    Yeah you are right, such a method should not contain an assert.

    I think the best solution is to just remove them!

    Best regards,
    marci4

  3. added a commit that references this issue on Apr 29, 2018
  4. marci4 commented on Apr 29, 2018

    @marci4
    Collaborator

    Issue is fixed by PR #702.

    Thank you again, @PhilipRoman.

    Best regards,
    marci4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions