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

Kill bot when stuck #883

Merged
merged 21 commits into from
Oct 21, 2022
Merged

Kill bot when stuck #883

merged 21 commits into from
Oct 21, 2022

Conversation

mplorentz
Copy link
Member

This should close #727 but also makes several other changes, because in order to reliably kill the Bot in the background I had to actually make sure we run regularly in the background.

I did a lot of real-world testing to try to learn more about the way iOS schedules background tasks and I learned several things and used them to improve the reliability of our background syncing code.

Unfortunately go-ssb cannot boot up and start replication fast enough to fit inside the lighter-weight (and more frequently scheduled) BGRefreshTask, which only gets about 20 seconds of runtime. Instead we need to rely on the heavier BGProcessingTask, which gets much more runtime (some people run tasks for several minutes) but basically only runs when the phone is charging and the user is not using it (so probably the middle of the night for most people). I introduced the concept of short syncs and long syncs in the code. We do still want to run short syncs when we get silent push notifications, although they rarely have enough time to get new messages. We'll also request longer syncs which do tend to get more messages.

I also did some refactoring of the Bot, removing some unused functions like syncNotifications and repoMessageCount, and synchronized all access to the ssbRepoStats() function because I was seeing weird behavior when it is called from multiple threads at once.

I also added some better analytics events for backgrounding syncing so we can see how effective this is in real world usage.

@mplorentz mplorentz marked this pull request as ready for review October 6, 2022 21:31
@mplorentz
Copy link
Member Author

I've been running this branch and the Patchwork feed algorithm feels really slow. Not sure what that's about but I'm going to investigate.

@mplorentz mplorentz marked this pull request as draft October 12, 2022 13:05
@mplorentz
Copy link
Member Author

We could do more to improve our background syncing in general, but this PR is doing what it is supposed to. It kills the bot when it gets stuck. And frequently it gets new messages when it is run in the background. I put together some stats to show this: https://app.posthog.com/dashboard/53168

This is ready for a review now @martindsq.

@mplorentz mplorentz marked this pull request as ready for review October 13, 2022 15:09
@martindsq martindsq merged commit 4c9ae44 into main Oct 21, 2022
@martindsq martindsq deleted the kill-bot-when-stuck branch October 21, 2022 16:33
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.

Check for go-ssb being stuck while the app is in the background and restart
2 participants