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

AssertionError at WebSocketImpl.isOpen #694

Closed
PhilipRoman opened this issue Apr 14, 2018 · 2 comments
Closed

AssertionError at WebSocketImpl.isOpen #694

PhilipRoman opened this issue Apr 14, 2018 · 2 comments

Comments

@PhilipRoman
Copy link
Collaborator

PhilipRoman commented Apr 14, 2018

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);
}
@marci4 marci4 added the Bug label Apr 16, 2018
@marci4 marci4 added this to the Release 1.3.9 milestone Apr 16, 2018
@marci4
Copy link
Collaborator

marci4 commented Apr 16, 2018

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

marci4 added a commit that referenced this issue Apr 29, 2018
Removed assertion from WebSocketImpl.isOpen (see #694)
@marci4
Copy link
Collaborator

marci4 commented Apr 29, 2018

Issue is fixed by PR #702.

Thank you again, @PhilipRoman.

Best regards,
marci4

@marci4 marci4 closed this as completed Apr 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants