-
Notifications
You must be signed in to change notification settings - Fork 4k
Enable better file uploading on Android #13132
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
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
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.
Pull request overview
This PR fixes a bug where file uploads fail on Android due to WebSocket disconnection when selecting files. The solution implements a request queue that stores file URL requests made while disconnected and processes them when the connection is re-established.
Key Changes
- Adds a queue mechanism to handle file URL requests during WebSocket disconnections
- Processes queued requests automatically when connection is restored
- Updates tests to verify queuing and processing behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| frontend/app/src/App.tsx | Implements pendingFileURLRequests queue, modifies requestFileURLs to queue when disconnected, adds processPendingFileURLRequests method to process queue on reconnection |
| frontend/app/src/App.test.tsx | Updates existing test description and adds new test case for verifying queued requests are processed on reconnection |
Comments suppressed due to low confidence (1)
frontend/app/src/App.tsx:817
- The
pendingFileURLRequestsqueue is never cleared when the connection is permanently lost. While this may not be a significant issue in production (as the page would typically be refreshed), it's good practice to clear the queue on permanent disconnection to prevent unbounded memory growth.
Recommended fix: Clear the queue when transitioning to DISCONNECTED_FOREVER state in handleConnectionStateChanged:
} else {
// If we're starting from the CONNECTED state and going to any other
// state, we must be disconnecting.
if (this.state.connectionState === ConnectionState.CONNECTED) {
this.hostCommunicationMgr.sendMessageToHost({
type: "WEBSOCKET_DISCONNECTED",
attemptingToReconnect:
newState !== ConnectionState.DISCONNECTED_FOREVER,
})
}
// Clear pending file requests on permanent disconnection
if (newState === ConnectionState.DISCONNECTED_FOREVER) {
this.pendingFileURLRequests = []
}
if (this.sessionInfo.isSet) {
this.sessionInfo.disconnect()
}
} } else {
// If we're starting from the CONNECTED state and going to any other
// state, we must be disconnecting.
if (this.state.connectionState === ConnectionState.CONNECTED) {
this.hostCommunicationMgr.sendMessageToHost({
type: "WEBSOCKET_DISCONNECTED",
attemptingToReconnect:
newState !== ConnectionState.DISCONNECTED_FOREVER,
})
}
if (this.sessionInfo.isSet) {
this.sessionInfo.disconnect()
}
}
| * See: https://github.com/streamlit/streamlit/issues/11419 | ||
| */ | ||
| export const WEBSOCKET_TIMEOUT_MS = 15 * 1000 | ||
| export const WEBSOCKET_TIMEOUT_MS = isAndroidDevice() ? 60 * 1000 : 15 * 1000 |
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.
60 seconds should be a lot less annoying for uploading files compared to 15 seconds timeout.
sfc-gh-lwilby
left a comment
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.
This looks like a good mitigation. Thanks!
Describe your changes
Use a higher websocket timeout on Android and better error message to improve file uploading on Android. Currently, this doesn't work if the user needs more than 15 seconds to choose a file since the websocket connection disconnects.
From my research, a proper fix for this would be quite complicate.
I manually verified on Android that this change works and makes it a lot more convenient to choose files.
GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.