Skip to content

Don't crash SDK is socket.close() fails #2216

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

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion firebase-database/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 19.5.1 (Unreleased)
# Unreleased
- [fixed] Fixed a crash on some Pixel devices that occurred when closing the
network connection.
- [added] Added `Query.get()`, which allows users to receive a single data
snapshot. `Query.get()` returns the latest value even if an older value
already exists in cache.

# 19.5.1
- [fixed] Fixes a regression in v19.4 that may cause assertion failures,
especially when persistence is enabled.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ private synchronized void closeSocket() {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (Throwable e) {
Copy link
Member

Choose a reason for hiding this comment

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

catching Throwable seems a little bit aggressive as it will also catch java.lang.Errors which, according to its javadoc, "a reasonable application should not try to catch". Would it be sufficient to only catch Exception for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I only mean to catch IOException and NPEs here.

eventHandler.onError(new WebSocketException("Failed to close", e));
}
}
state = State.DISCONNECTED;
Expand Down