Skip to content

Fix race condition in player#2750

Closed
Luna712 wants to merge 2 commits intorecloudstream:masterfrom
Luna712:fix-race
Closed

Fix race condition in player#2750
Luna712 wants to merge 2 commits intorecloudstream:masterfrom
Luna712:fix-race

Conversation

@Luna712
Copy link
Copy Markdown
Contributor

@Luna712 Luna712 commented May 2, 2026

Fixes #2746

I was unable to reproduce the issue after this, but also it doesn't happen every single time anyway so I can not be 100% certain this fully fixes it, though seemed to.

Copy link
Copy Markdown
Collaborator

@fire-light42 fire-light42 left a comment

Choose a reason for hiding this comment

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

  1. Please change currentLinks+currentSubs to ConsistentLiveData if you want to do this.
  2. Please see filterSubByLang.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented May 2, 2026

  1. Please change currentLinks+currentSubs to ConsistentLiveData if you want to do this.
  2. Please see filterSubByLang.

@fire-light42

I think I did what you mean?

@Luna712 Luna712 requested a review from fire-light42 May 2, 2026 19:01
@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented May 3, 2026

@fire-light42 I wonder if you could also perhaps explain to me a little bit what ConsistentLiveData does and when it should be used? I'm having a hard time understanding it's code, but am curious at least when it is something that should be used.

@fire-light42
Copy link
Copy Markdown
Collaborator

@fire-light42 I wonder if you could also perhaps explain to me a little bit what ConsistentLiveData does and when it should be used? I'm having a hard time understanding it's code, but am curious at least when it is something that should be used.

ConsistentLiveData is used to avoid the threading issue with LiveData. To be more precise, LiveData is "thread-safe", but only makes its value "visible" after it writes the value in the main thread. This means that:

live.postValue(x)
println(live.value) // Not necessarily "x" when on a non-main thread

ConsistentLiveData is simply a LiveData with a backing volatile variable, so it becomes visible immediately when using .value. See more in the doc comment on ConsistentLiveData.

In general you should never have to use .value given that observe should only be used for UI. However, to solve this problem we use ConsistentLiveData to solve thread issues whenever we need to access .value.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented May 3, 2026

That makes a ton of sense and I really appreciate you taking the time for the explanation, thanks a ton for that and it will be helpful for me in the future I think.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented May 4, 2026

I think I may have a better way to do thia soon that fixes the underlying issue in the view model rather than relying on this before startPlayer. I am testing and will let you know if this method should be merged or not once I see if it is going to work well. My way fixes a bunch of race conditions and allows full process death restoration and fixes numerous other bugs also. I am just mentioning here so this shouldnt be merged yet if this works out. I will update here within a couple days.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented May 4, 2026

@fire-light42 there is a very easy much better fix for this I will push later.

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.

No Links Found bug in DownloadedPlayerActivity

2 participants