-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
fix: stuck MJPEG clients when one client fails to initialize #676
Conversation
There was an issue with the Client implementation: if a socket started a connection on the internal MJPEG port and was never initialized, the entire server thread would be stuck in the while loop waiting for initialization. This broke other clients connected to the server: no frames would be received anymore. To reproduce on emulator / real device: - start an Appium server with mJPEG server enabled (`appium:mjpegServerPort:9100` for instance) - Start an Appium session that reads the mJPEG frames (using Appium Inspector for instance) - Then from `adb shell`: connect to the internal mJPEG server (default port 7810): `nc localhost 7810` - --> Streaming will be broken for the existing clients This fixes the problem by returning early: if the client is not ready initialization will be retried later if necessary (or never) instead of blocking the thread Another side effect is that we actually receive frames from `nc localhost 7810` instead of it being stuck
The committers listed above are authorized under a signed CLA. |
@@ -0,0 +1,75 @@ | |||
package io.appium.uiautomator2.server.mjpeg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
## [7.1.9](v7.1.8...v7.1.9) (2024-12-31) ### Bug Fixes * stuck client when socket client never initializes ([#676](#676)) ([34161a3](34161a3))
🎉 This PR is included in version 7.1.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi @vbarbaresi, congrats: the Appium project wants to compensate you for this contribution! Please reply to this comment mentioning @jlipps and @KazuCocoa and sharing your OpenCollective account name, so that we can initiate payment! Or let us know if you decline to receive compensation via OpenCollective. Thank you! |
Hi, thanks for the proposition, it's much appreciated! |
Thanks for letting us know, hope to see you again @vbarbaresi :-) |
Problem
There was an issue with the Client implementation: if a socket started a connection on the internal MJPEG port and was never initialized, the entire server thread would be stuck in the while loop waiting for the client to send something.
This broke other clients connected to the server: no frames would be received anymore.
To reproduce on emulator / real device:
appium:mjpegServerPort:9100
for instance)adb shell
: connect to the internal mJPEG server (default port 7810):nc localhost 7810
nc localhost 9100
This happens because the client connection is not sending a proper HTTP request: it simply tries to receive data and this wasn't supported.
In this particular case we should not wait forever and not stop streaming frames to other clients
Fix details
This patch fixes the problem by returning early: if the client is sending anything, initialization will be retried later if necessary instead of blocking the thread.
Another side effect is that we now actually receive frames using
nc localhost 9100
: this command was previously stuck waiting for the client to send something.This can be useful for checking the status of the MJPEG server if we don't have a proper HTTP client handy
I added a unit test reproducing the bug by opening a socket connection to the MJPEG server and closing it without sending any data. Then verified that the server still works for another HTTP client. This test wouldn't pass before the fix