Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Firebase have a timeout policy for write operations?

There is setValue( ) to save data to Firebase. What happens if the connection is very very slow. Is there a timeout limit for saving data? If it does timeout, does it retry? If it retries, how many times?

Also, Is there timeout for reading method onDataChange(DataSnapshot snapshot) and updating methods?

Is there a way to set your own timeout limits?

like image 915
Shreyans jain Avatar asked Jan 16 '16 10:01

Shreyans jain


1 Answers

When a client first connects to Firebase (so when it executes the first new Firebase(...), it establishes a WebSocket connection to the server. After that all data is transferred over that pre-established connection.

When you call setValue() or another write operation, the command is sent over the open socket to the server. When a client adds a listener (with addValueEventListener() or similar), the server will send updates over the open socket to your client. Since there is no connection being established, time-outs don't really come into play here.

When the connection between client and server is somehow lost, the client will try to re-establish the connection. It uses an exponential back-off here, so initially it frequently tries to reconnect and progressively less frequently.

While there is no connection to the server, the client will keep serving all data it already received from its in memory (or on-disk if you've enabled disk persistence) cache. Any write operations from the client will be queued for sending to the server. Local events (that trigger e.g. your onDataChange() method) will trigger right away, even while the client is not connected to the server.

This covers a lot of ground. If you want to learn more about how this works, your best bet is to enable debug logging (Firebase.getDefaultConfig().setLogLevel(Level.DEBUG) in the Android client) and inspect what appears in the logging output when you drop your network connection. It's highly educational and will answer more questions than I ever can here.

like image 200
Frank van Puffelen Avatar answered Oct 30 '22 07:10

Frank van Puffelen