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

Avoid thread-starvation in BackgroundTaskService #1768

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

lemnik
Copy link
Contributor

@lemnik lemnik commented Oct 17, 2022

Goal

Avoid possible thread starvation when submitting tasks to the BackgroundTaskService.

Design

Changed the BackgroundTaskService to internally be able to identify its threads. When the result of a Future is queried it will first check to see if the task is incomplete && is queued to be executed on the current thread. If so the task is run immediately and the result is returned.

Testing

A new unit test was added that causes thread starvation by adding a task to each queue, which then adds a task to the same queue and then blocks on both tasks to await their completion. This triggers a deadlock as the first task waits for itself to complete.

@lemnik lemnik requested a review from kstenerud October 17, 2022 15:34
@lemnik lemnik force-pushed the PLAT-8892/fix-possible-thread-starvation branch from 62be2d5 to 67e8de7 Compare October 17, 2022 15:35
@bugsnagbot
Copy link
Collaborator

bugsnagbot commented Oct 17, 2022

Android notifier sizes

Format Size impact of Bugsnag (kB) Size impact of Bugsnag when Minified (kB)
APK 1915.67 1693.28
arm64_v8a 676.24 455.05
armeabi_v7a 610.71 393.62
x86 754.04 532.86
x86_64 721.28 500.1

Generated by 🚫 Danger

@lemnik lemnik requested review from tomlongridge and removed request for kstenerud and tomlongridge October 17, 2022 15:55
@lemnik lemnik force-pushed the PLAT-8892/fix-possible-thread-starvation branch from 67e8de7 to 3d8f8b0 Compare October 17, 2022 16:55
…queue submitting the work to avoid possible thread starvation
@lemnik lemnik force-pushed the PLAT-8892/fix-possible-thread-starvation branch from 3d8f8b0 to e898f68 Compare October 17, 2022 17:16
Copy link
Contributor

@tomlongridge tomlongridge left a comment

Choose a reason for hiding this comment

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

Changelog LGTM

@lemnik lemnik merged commit ca00b3f into next Oct 18, 2022
@lemnik lemnik deleted the PLAT-8892/fix-possible-thread-starvation branch October 18, 2022 16:23
@lemnik lemnik mentioned this pull request Oct 19, 2022
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.

4 participants