Fix FragmentfailureRampdown thread safety and divide-by-zero#1371
Open
benmesander wants to merge 2 commits intodev_sprint_25_2from
Open
Fix FragmentfailureRampdown thread safety and divide-by-zero#1371benmesander wants to merge 2 commits intodev_sprint_25_2from
benmesander wants to merge 2 commits intodev_sprint_25_2from
Conversation
Add mProfileLock guard when copying mProfiles in FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition. Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf. For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly. These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing. Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens ABR rampdown logic by fixing a thread-safety issue when copying the profile list during FragmentfailureRampdown, and by preventing a floating-point divide-by-zero when abrMaxBuffer is unset/zero. It also adds unit tests to validate the new guard behavior.
Changes:
- Add
abrMaxBuffer <= 0guard inFragmentfailureRampdownto avoid divide-by-zero (new and legacy ABR). - Make copying of
mProfilesthread-safe during rampdown (new ABR via lock; legacy ABR via new locked accessor). - Add L1 unit tests covering the
abrMaxBuffer == 0rampdown behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
abr/abr.cpp |
Adds abrMaxBuffer guard and locks mProfiles while copying in FragmentfailureRampdown. |
support/aampabr/HybridABRManager.cpp |
Adds abrMaxBuffer guard and uses a new locked profile-copy helper in rampdown. |
support/aampabr/ABRManager.h |
Adds getProfileInfoLocked() API for thread-safe access to the profile list. |
support/aampabr/ABRManager.cpp |
Implements getProfileInfoLocked() by copying mProfiles under mProfileLock. |
test/utests/tests/AampAbrTests/AbrTests.cpp |
Adds a unit test asserting rampdown returns 0 when abrMaxBuffer == 0 (new ABR). |
test/utests/tests/AampAbrTests/HybridAbrTests.cpp |
Adds a unit test asserting rampdown returns 0 when abrMaxBuffer == 0 (legacy ABR). |
Comment on lines
+294
to
+298
| /** | ||
| * @brief Get a thread-safe copy of the profile list | ||
| * @return Copy of mProfiles taken under mProfileLock | ||
| */ | ||
| std::vector<ProfileInfo> getProfileInfoLocked(); |
Comment on lines
+1123
to
+1124
| AAMPLOG_ERR("abrMaxBuffer is %d, cannot compute buffer percentage", | ||
| eAAMPAbrConfig.abrMaxBuffer); |
Comment on lines
1117
to
+1121
| * @return - desired profile based on buffer | ||
| */ | ||
| BitsPerSecond ABRManager::FragmentfailureRampdown(int currentBuffer, int currentProfileIndex) | ||
| { | ||
| if (eAAMPAbrConfig.abrMaxBuffer <= 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add mProfileLock guard when copying mProfiles in
FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition.
Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf.
For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly.
These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing.
Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard.