1

In my app, I already have a way of checking if the user has a problem with the internet connection thus I have already handled these cases (I am using the Realtime Database, authentication, and cloud functions). But is there a way of knowing beforehand if the server itself is having problems (like an outage, downtime, etc.) and not when I check for the failed Task in the onComplete callback? I remember reading somewhere that if this statement

FirebaseApp.getInstance()

throws an IllegalStateException it basically means that Firebase isn't available, but I am not sure if that is true or if it is exactly what I need.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Can you share complete error log? – Dharmaraj Jul 28 '21 at 11:39
  • @Dharmaraj There is no error log. It hasn't happened to me yet I just want to prepare for such case (If the server is having an outage, downtime etc.) – Veselin Zinkov Jul 28 '21 at 11:42
  • i doubt anything you try will be useful or relevant to you, if there isn't a value you can _observe_ on, then there's always the possibility of the server going down between the time you check and the time your request executes – a_local_nobody Jul 28 '21 at 11:43
  • Have you checked [detecting network state](https://firebase.google.com/docs/database/android/offline-capabilities#section-connection-state)? You can use realtime db to check if user is connected to internet. – Dharmaraj Jul 28 '21 at 11:44
  • @Dharmaraj Yes I have, but as I said I already have a way of checking if the user is connected to the internet. – Veselin Zinkov Jul 28 '21 at 11:45
  • @Dharmaraj `You can use realtime db to check if user is connected to internet.` that's not what OP is asking, they're asking for a way to check if firebase is down – a_local_nobody Jul 28 '21 at 11:45
  • @a_local_nobody Of course there's always that possibility, but it's better to check than not at all. At least that's what I think. – Veselin Zinkov Jul 28 '21 at 11:49
  • That's interesting. I'm not if there's anything to check status of all Firebase services that way. Have you checked [this answer](https://stackoverflow.com/questions/38374185/how-to-check-if-firebase-service-is-available) – Dharmaraj Jul 28 '21 at 11:50
  • @Dharmaraj That's exactly where I got my suggestion above. I couldn't find the answer earlier. But as I said I am not sure that it is reliable. https://stackoverflow.com/a/62595363/11456922 – Veselin Zinkov Jul 28 '21 at 12:09
  • ironically, that just means your question is a duplicate and it will probably be closed, unfortunately – a_local_nobody Jul 28 '21 at 12:10
  • @a_local_nobody I mean that question was posted like 5 years ago and there isn't even an accepted answer. So I hoped that things might have changed and someone could give a concrete answer (That's why I asked the question). But if it's considered a duplicate so be it. – Veselin Zinkov Jul 28 '21 at 12:17

1 Answers1

2

In my app I already have a way of checking if the user has a problem with the internet connection

If your solution is similar to this one:

Then you should go ahead with it.

But is there a way of knowing beforehand if the server itself is having problems (like an outage, downtime, etc.)

As in the above example, to know if you have an internet connection, you simply ping Google servers, which are unlikely to be down. Since Firebase servers are apart from Google, you can use that solution similarly.

If you want something more advanced, you can create an HTTP request, and check the status against your Firebase Project URL. To know the server response, handle the error by checking the error message for the status codes. Please see below a list of all available HTTP response status codes:

and not when I check for failed tasks in the onComplete callback.

If your onComplete is triggered, it means that Firebase servers accepted, or rejected your request, according to the state of the Task object. This can be successful or not. If it's not, it doesn't mean that the Firebase servers are down. It means that the request was rejected most likely due to a Firebase Security Rule issue.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I thought that when there is a server issue the request would instantly get rejected (apparently not). So thanks for that little clarification. My solution about checking if the user has internet connection is not similar to the one you have proposed, but it makes sense to do it just like that so I will try to implement it. Sorry if this next question is a little silly, but if I am pinging Google servers will it be able to detect problems with Firebase servers or what exactly do you mean by "you can use that solution similarly". Again sorry if the question is silly. – Veselin Zinkov Jul 28 '21 at 13:15
  • What I meant, is in the same way you are pinging Google servers (google.com), you can also ping Firebase servers, to see if you get a response. If you don't get a response, most likely the server is down. I used that solution, but I never got such a response. However, it's a good practice to check against internet availability. – Alex Mamo Jul 28 '21 at 13:19
  • Another question: Because I am not familiar with pinging (I understand the concept but I have never done it) will I be able to ping directly my Realtime Database through its url? – Veselin Zinkov Jul 28 '21 at 13:31
  • Most likely you should ping the server IP on which the website is hosted. – Alex Mamo Jul 28 '21 at 13:45
  • I think I am going to settle for your second suggestion and create an HTTP request and just check the availability with my Realtime Database URL. Would you say that this https://java2blog.com/how-to-ping-url-and-get-status-in-java is a good example? – Veselin Zinkov Jul 28 '21 at 14:21
  • I didn't try the exact solution in that URL, but at a first glance, looks good. Give it a try, and see if it fits your needs. – Alex Mamo Jul 28 '21 at 14:51
  • 1
    Alright, thank you for your help. I really appreciate it. – Veselin Zinkov Jul 28 '21 at 15:02