rollbar / rollbar-ios

Objective-C library for crash reporting and logging with Rollbar.
https://docs.rollbar.com/docs/ios
MIT License
65 stars 61 forks source link

Events logged while app is in background are not reported to Rollbar #317

Closed tdipiazza closed 3 years ago

tdipiazza commented 4 years ago

Hi!

We've noticed that certain Rollbar events are not firing while an app is in a backgrounded state. Specifically, we're trying to log a critical event to Rollbar before forcing a crash in certain cases where the app has entered an unstable state.

I was able to reproduce this in a separate sample application by wiring up a button to force a crash after sleeping for 10 seconds to allow time to put the app into a backgrounded state.

    @IBAction func RollbarCrashButton(_ sender: Any) {

        sleep(10)

        Rollbar.critical(fatalMessage + " - Rollbar Log Critical Test")
        preconditionFailure(fatalMessage + " - Failure assertion - Rollbar")
    }

I occasionally also see this message logged to the console when I relaunch in debug mode: 2020-09-01 16:30:28.574989-0500 TestForceCrash[64273:4729792] [Rollbar] Error restoring data from file to JSON: {length = 92733, bytes = 0x7b226461 7461223a 7b226375 73746f6d ... 63656235 30227d0a }

akornich commented 4 years ago

@tdipiazza , thanks for reporting the issue!

I just want to make sure I understand the problem correctly: when you say " certain Rollbar events are not firing while an app is in a backgrounded state" and based on your code sample, you mean that this payload does not get logged: Rollbar.critical(fatalMessage + " - Rollbar Log Critical Test")? You are not talking about the subsequent crash report not being reported?

When the problem happens, do you see the expected payload within the rollbar.items file?

The error you seeing the console ([Rollbar] Error restoring data from file to JSON) leads me to believe that either invalid JSON was saved into the file or there is some sort of file corruption.

BTW, what version of this SDK are you using?

tdipiazza commented 4 years ago

Correct - I'm referring to the Rollbar.critical() payload not being logged.

rollbar.items and rollbar.payload are empty.

I'm on version 1.12.9 of the SDK.

akornich commented 4 years ago

@tdipiazza , thanks for the clarification! in case you are integrating the SDK via source code (i.e as a CocoaPod or a Git submodule), may i ask you to see how error looks like when this line is called and the resulting payload is nil (that would cause the error message in the console)?

akornich commented 4 years ago

@tdipiazza , one more question. in your repro app, when the application goes into the background and the expected critical message not delivered to Rollbar, do you have an application crash log created at that time (i.e. the app goes into the background and eventually gets terminated producing a crash log)?

tdipiazza commented 4 years ago

I'm getting the error message in the console fairly inconsistently. I crashed in the background just now and there was no error. I do have a crash log. I've attached both the crashlog and payload contents here. payload-and-crash-log.zip

tdipiazza commented 4 years ago

Tried again, got a nil payload, error "Garbage at end"

Screen Shot 2020-09-03 at 9 53 53 AM

It also appears to succeed on a couple of subsequent attempts, and the error was nil when it hit the breakpoint on tries 2 and 3:

2020-09-03 09:55:10.794496-0500 TestForceCrash[9424:613352] [Rollbar] Error restoring data from file to JSON: {length = 91318, bytes = 0x7b226461 7461223a 7b226375 73746f6d ... 63656235 30227d0a } 2020-09-03 09:55:20.828524-0500 TestForceCrash[9424:613339] [Rollbar] Success 2020-09-03 09:55:26.006397-0500 TestForceCrash[9424:613348] [Rollbar] Success

akornich commented 4 years ago

@tdipiazza , thanks for the provided data! Do you think the iOS Watchdog terminates your test app while it is sleeping for 10 sec? That would explain that Rollbar.critical(...) does not ever get executed...

Also, the NSError you captured (Xcode screen shot) tells me that the stored line of data for a payload item is a malformed JSON. Hence, the console message about "[Rollbar] Error restoring data from file to JSON..." that also would mean we are not even attempting to send that payload item.

In the test app, is this the only place where you are trying to send a log to Rollbar?: Rollbar.critical(fatalMessage + " - Rollbar Log Critical Test")

akornich commented 4 years ago

@tdipiazza , just wanted to check with you on the status of this issue...

akornich commented 3 years ago

closing due to no responses...