Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last phase of OOM refactoring. #820

Merged
merged 3 commits into from
Oct 2, 2020
Merged

Last phase of OOM refactoring. #820

merged 3 commits into from
Oct 2, 2020

Conversation

kstenerud
Copy link
Contributor

@kstenerud kstenerud commented Sep 24, 2020

  • Replaced BSGOutOfMemoryWatchdog with BugsnagSystemState.
  • Moved OOM detection into BugsnagClient, which uses BugsnagSystemState as its information source.
  • Stronger and more explicit OOM heuristics.
  • OOM detection now relies entirely upon last launch state (includng debugger status).

Under the new system, you can cause an out of memory shutdown while the app is not being debugged, and then launch it in a debugger to observe it sending an OOM event (bringing the OOM behaviour in-line with the other events). Any sudden shutdowns while a debugger is active won't generate an OOM event (same as before).

OOMs are now enabled by default on DEBUG builds (like on RELEASE builds). We don't need this distinction anymore since the library records whether it was being debugged or not.

We should still add more heuristics later. All heuristics are contained and explained in a single easy-to-follow method "didLikelyOOM" in BugsnagClient.

Testing

Testing was done using the app's OOM test, as well as using Xcode to simulate sudden shutdowns in various situations (simulating the sudden shutdowns that the OOM handler looks for in its heuristics).

All testing was performed in release mode.

Testing debugger detection:

To test debugger detection, I turned the debugger on/off while triggering a sudden termination in between.

Debugger OOM?
ON, ON No
ON, OFF No
OFF, OFF Yes
OFF, ON Yes

Other testing:

These were run with no debugger in order to verify the behaviour in various situations.

Test OOM?
Run OOM test in example app Yes
Background, then terminate app No
Shutdown app normally No
Launch, terminate, change version, launch No
Launch, terminate, launch Yes

@kstenerud kstenerud changed the base branch from master to next September 24, 2020 12:10
@kstenerud kstenerud force-pushed the 751-oom-changes branch 5 times, most recently from 3af0a94 to fea74b9 Compare September 24, 2020 14:27
/**
* These heuristics aren't 100% guaranteed to be correct, but they're correct often enough to be useful.
*/
- (bool)didLikelyOOM {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this method into BugsnagSystemState?

It would help reduce the size of BugsnagClient a bit, and the method doesn't access anything in the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to keep BugsnagSystemState's purpose to only recording information rather than interpreting it.

Of course, BugsnagClient isn't really the ideal place to interpret it either I suppose...

@kstenerud kstenerud force-pushed the 751-oom-changes branch 2 times, most recently from 9433454 to 61d78b6 Compare September 28, 2020 11:08
@kstenerud
Copy link
Contributor Author

Update: I've had to add special "purge" methods to allow resetting persistent state since many of the tests make assumptions about the state at the start of the test. I suspect that many tests are actually wrong in their assumptions, but work because they happen to run in a particular order. We'll need to decide how we want to ensure a deterministic start state in our tests at some point, because otherwise this will keep biting us.

I've also had to modify one of the stack trace interpretation tests because something on my computer is now producing slightly different data for the same test.

@kstenerud kstenerud force-pushed the 751-oom-changes branch 3 times, most recently from 28ed532 to 16cb3ed Compare September 28, 2020 14:59
- Replaced BSGOutOfMemoryWatchdog with BugsnagSystemState.
- Moved OOM detection into BugsnagClient, which uses BugsnagSystemState as its information source.
- Stronger and more explicit OOM heuristics.
- OOM detection now relies entirely upon last launch state (includng debugger status).

Under the new system, you can cause an out of memory shutdown while the app is not being debugged, and then launch it in a debugger to observe it sending an OOM event. Any sudden shutdowns while a debugger is active won't generate an OOM event (as before).

We should still add more heuristics later. All heuristics are contained and explained in a single easy-to-follow method "didLikelyOOM" in BugsnagClient.
Copy link
Contributor

@kattrali kattrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, raised one nit about the changelog

CHANGELOG.md Outdated Show resolved Hide resolved
@kstenerud kstenerud merged commit 25905d5 into next Oct 2, 2020
@kstenerud kstenerud deleted the 751-oom-changes branch October 2, 2020 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants