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

Better handling of closed stream errors #1304

Merged
merged 11 commits into from
Dec 3, 2024
Merged

Better handling of closed stream errors #1304

merged 11 commits into from
Dec 3, 2024

Conversation

akberenz
Copy link
Member

@akberenz akberenz commented Nov 2, 2024

Addresses the issue in #1300 where streams will continue to attempt sending data to a closed stream until explicitly closed.

}
catch(DeviceException e) {
catch(WebSocketException | DeviceException e) {
// Calling usb.close() can cause a hard-crash on macOS
Copy link
Contributor

@tresf tresf Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vzor- I thought we had gracefully handled this in our upstream PR, but somehow I'm able to crash the app here if I call usb.close(). gary-rowe/hid4java#153.

I'm leaving this comment in the source code for now as a future warning.

Crashing it's pretty easy, just change usb.setStreaming(false) to usb.close() and close the tab while the device is streaming.

@tresf
Copy link
Contributor

tresf commented Dec 3, 2024

Testing this... sadly, the ClosedChannelException is being wrapped in an IOException which is causing the explicit catches to not fire. Investigating...

[ERROR] 2024-12-03T13:12:37,022 @ qz.ws.PrintSocketClient:834
	Could not send message
java.io.IOException: java.nio.channels.ClosedChannelException
	at org.eclipse.jetty.util.FutureCallback.block(FutureCallback.java:163) ~[jetty-util-10.0.22.jar:10.0.22]
	at org.eclipse.jetty.util.FutureCallback.block(FutureCallback.java:139) ~[jetty-util-10.0.22.jar:10.0.22]
	at org.eclipse.jetty.websocket.common.JettyWebSocketRemoteEndpoint.sendBlocking(JettyWebSocketRemoteEndpoint.java:191) ~[websocket-jetty-common-10.0.22.jar:10.0.22]
	at org.eclipse.jetty.websocket.common.JettyWebSocketRemoteEndpoint.sendString(JettyWebSocketRemoteEndpoint.java:52) ~[websocket-jetty-common-10.0.22.jar:10.0.22]
	at qz.ws.PrintSocketClient.send(PrintSocketClient.java:828) ~[production/:?]
	at qz.ws.PrintSocketClient.sendError(PrintSocketClient.java:768) ~[production/:?]
	at qz.ws.PrintSocketClient.processMessage(PrintSocketClient.java:375) ~[production/:?]
	at qz.ws.PrintSocketClient.lambda$onMessage$0(PrintSocketClient.java:171) ~[production/:?]
	at java.base/java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.nio.channels.ClosedChannelException
	at org.eclipse.jetty.websocket.core.internal.WebSocketSessionState.onOutgoingFrame(WebSocketSessionState.java:184) ~[websocket-core-common-10.0.22.jar:10.0.22]
	at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.sendFrame(WebSocketCoreSession.java:514) ~[websocket-core-common-10.0.22.jar:10.0.22]
	at org.eclipse.jetty.websocket.common.JettyWebSocketRemoteEndpoint.sendBlocking(JettyWebSocketRemoteEndpoint.java:190) ~[websocket-jetty-common-10.0.22.jar:10.0.22]
	... 6 more

@tresf
Copy link
Contributor

tresf commented Dec 3, 2024

Testing this... sadly, the ClosedChannelException is being wrapped in an IOException which is causing the explicit catches to not fire. Investigating...

I think this is fixed via f0e3754.

@tresf tresf merged commit b1573f8 into master Dec 3, 2024
12 checks passed
@tresf tresf deleted the closed-channel-errors branch December 3, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants