Single....blockingGet() hangs in RxJava 2.1.3 when using Android/Firebase
See original GitHub issueWhen using the following pattern to synchronously get data from Firebase Realtime Database:
String s = Single.create(new SingleOnSubscribe<String>() {
@Override
public void subscribe(SingleEmitter<String> e) throws Exception {
FirebaseDatabase.getInstance().getReference("path").orderByChild("child")
.equalTo("xyz").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
e.onSuccess("Got it");
}
@Override
public void onCancelled(DatabaseError databaseError) {
e.onError(databaseError.toException());
}
});
}
}).blockingGet();
It will hang and create an ANR error. If I use the same Firebase “innards” outside of the Single, it fires just fine. The Single without the Firebase code inside also will fire, so it seems there is some incompatibility between the two.
[Apologies on the formatting, I can’t for the life of me get it to look nice]
Any ideas?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Single.Create()...blockingGet() hangs in RxJava 2.1.3 when ...
Firebase delivers events on ui thread, waiting for result with blockingGet deadlocks it. In my opinion you should rethink app logic and ...
Read more >signal | javascript reactive programming - kandi - Open Weaver
Implement signal with how-to, Q&A, fixes, code snippets. kandi ratings - Low support, No Bugs, No Vulnerabilities. Permissive License, Build not available.
Read more >Single.Create()...blockingGet() hangs in RxJava 2.1.3 when using ...
When using the following pattern to anycodings_firebase synchronously get data from Firebase anycodings_firebase Realtime Database: String s = Single.create(new ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If
blockingGet
doesn’t return it means theValueEventListener
was not called. We had some issues when dealing with Android features that use weak references for their listeners: If you don’t have a strong reference to them, they may disappear and events are never signalled. Try this:Also blocking on the main thread is discouraged so not sure on which you blocked originally and in your Rx. Assuming from the ANR that you block the main thread and the Firebase listener signals on the main thread but can’t since you are blocking it, hence a deadlock.
Please try replacing
blockingGet
withsubscribe
? If it works, then please consider my comment again: