haroldadmin / WhatTheStack

See a pretty error screen when your Android app crashes
Apache License 2.0
245 stars 22 forks source link

Error screen does not work if the app crashes very quickly after launching #3

Open haroldadmin opened 4 years ago

haroldadmin commented 4 years ago

The library relies on a service running in a different process to process and display the error screen. This means that if the application crashes immediately after start, the service might not get enough time to be prepared for accepting new messages.

Unfortunately it looks like there is no easy solution for this problem.

prudhvir3ddy commented 3 years ago

@haroldadmin does this mean that issue is in app startup library ?

prudhvir3ddy commented 3 years ago

verified using debugger that whatthestack is getting initialised first but the service starting is taking the time.

haroldadmin commented 3 years ago

You got it right, the problem occurs because the service takes a short while to start.

The issue has been open for so long because, unfortunately, I have not found a good solution for it.

matejdro commented 2 years ago

Here is a possible way:

  1. If crash happens and service has not yet been connected store stacktrace to the disk
  2. When service (in another process) starts, poll disk for couple of seconds in case crash has been written
  3. Display crash from disk
haroldadmin commented 2 years ago

I'll have to verify if the app crash halts the service's startup process, otherwise serializing the crash for later consumption is a nice idea. Can't promise an ETA :)

haroldadmin commented 2 years ago

I experimented with the idea of serializing the crash for deferred use in the service. I opted to use a JSON file in the app's private directory because:

Here's the system I implemented:

The idea was that now the FileObserver would trigger the error screen instead of a Message from the exception handler. I also added code to account for the observer not getting a change notification right at the start of the service, as well as cleaning up the private file after triggering the error screen to prevent duplicate notifications.

This system works, but unreliably. It missed roughly 1 out of every 5 crashes, and I suspect that's down to multi-process file IO synchronization issues. It's a neat solution to the problem in theory, but falls apart in reliability. I might experiment with DB-based serialization in the future.

An important observation from this experiment was that the service continues its init process as usual even if the main application crashes.

matejdro commented 2 years ago

Maybe instead of file observer, you could rely on service like in the current version + polling the file for first couple of seconds (until service is connected)?