-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Deadlock in PlaylistViewController #3405
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
Comments
Do you happen to have the entire sample (or even better, a spindump targeting the process)? |
As it so happens |
AnalysisThis is a regression introduced by this commit added Feb 27, 2020: This commit says it reverts the following commit: But that commit did not modify Neither commit mentions an issue number. Apparently something was going wrong with the total length displayed by the playlist. The cause appears to be related to mult-threaded access to the swift dictionaries BUT the clip from the spindump posted in the issue shows that The spindump shows the
The The method iina/iina/PlaylistViewController.swift Line 510 in 0bc3bf0
The task being submitted tries to obtain the duration for an entry in the playlist from iina/iina/PlaylistViewController.swift Line 534 in 0bc3bf0
As per this comment this is a long running method: /**
Get video duration, playback progress, and metadata, then save it to info.
It may take some time to run this method, so it should be used in background.
*/
func refreshCachedVideoInfo(forVideoPath path: String) {
guard let dict = FFmpegController.probeVideoInfo(forFile: path) else { return } The method Conclusions:
FixingI believe the proper Swift way to fix this issue with thread interaction is to use Actors and Async-await. But that is not currently an option. These language features have been added in Swift 5.5, which is available in Xcode 13, however at this time Xcode 13 is in beta. Still useful to be thinking about actors as knowing the future direction of Swift can influence how the fix is structured. When Swift 5.5 is available, we'd either refactor the The commit in the pull request I will be submitting shortly:
An advantage of making these dictionaries private to the class is that it forces a new programmer to look at the methods provided by the class which will then make it obvious to the programmer that the data is shared between threads and they had better be taking that into consideration when making changes. The current code is forcing single threaded access over a large set of operations. These changes reduce that to only single thread access to an individual dictionary. Is there some need for atomic access involving multiple dictionaries/data that I missed? Worries me that because I don't know the details of the issue that the current code fixed these changes could bring back that issue. There are other mutable dictionaries in Thoughts? Critical reviews including criticism of style and naming are welcome. Would be good to hear from @inflation and @Alejx as to whether these changes will break what the previous commits fixed. |
This commit: - Changes cachedVideoDurationAndProgress and cachedMetadata to be private to the PlaybackInfo class. - Adds a private DispatchQueue named lockQueue to coordinate thread access to the cache - Adds methods for operating on the cache dictionaries that use lockQueue to single thread the operations - Dedicates the DispatchQueue playlistQueue to background tasks This corrects a problem where the main thread is blocked waiting for a background task to finish.
* Fix deadlock in PlaylistViewController, #3405 This commit: - Changes cachedVideoDurationAndProgress and cachedMetadata to be private to the PlaybackInfo class. - Adds a private DispatchQueue named lockQueue to coordinate thread access to the cache - Adds methods for operating on the cache dictionaries that use lockQueue to single thread the operations - Dedicates the DispatchQueue playlistQueue to background tasks This corrects a problem where the main thread is blocked waiting for a background task to finish. * Add missing getCachedVideoDurationAndProgress Co-authored-by: low-batt <86170219+low-batt@users.noreply.github.com>
* Fix deadlock in PlaylistViewController, #3405 This commit: - Changes cachedVideoDurationAndProgress and cachedMetadata to be private to the PlaybackInfo class. - Adds a private DispatchQueue named lockQueue to coordinate thread access to the cache - Adds methods for operating on the cache dictionaries that use lockQueue to single thread the operations - Dedicates the DispatchQueue playlistQueue to background tasks This corrects a problem where the main thread is blocked waiting for a background task to finish. * Add missing getCachedVideoDurationAndProgress Co-authored-by: low-batt <86170219+low-batt@users.noreply.github.com>
The fix in PR #3699 has been merged into the develop branch. |
Closing. Fixed in IINA 1.3.0. |
Seems to be a deadlock at
iina/iina/PlaylistViewController.swift
Line 165 in 0bc3bf0
System and IINA version:
Expected behavior:
Actual behavior:
827 samples of frozen GUI:
mpv log:
Steps to reproduce:
How often does this happen?
Many times a day / every launch
The text was updated successfully, but these errors were encountered: