question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Thread deadlock when using the media2 extension

See original GitHub issue

[REQUIRED] Issue description

I am experiencing thread deadlocks on the project I am working on. It uses the new media2 extension and the latest Exoplayer library artifact versions (2.12.0). The issue occurs when a non-default Executor is being set as a callback executor to a MediaLibraryService.MediaLibrarySession.Builder. The created MediaLibrarySession is connected to a SessionPlayerConnector.

[REQUIRED] Reproduction steps

I’ve attached thread dumps at the end of the report which display what’s getting blocked and why. The issue reproduction depends on changes of the buffering state being reported to SessionPlayerConnector.setBufferingState().

At some point MediaSessionImpl… is calling SessionPlayerConnector.getBufferingState() which internally posts a callback to the main thread’s event loop, then blocks the thread waiting for the callback to execute (SessionPlayerConnector.runPlayerCallableBlocking()). The problem is this is all happening while an internal lock is being held inside MediaSessionImplBase.createPlaybackStateCompat(), which will not be released until the main thread looper processes the posted callbacks. At the same on the main thread event queue there’s a preceding callback which is trying to acquire the same lock, thus waiting forever.

To me it seems the preceding callback originates from a call to SessionPlayerConnector.notifySessionPlayerCallback() and has something to do with the following code and comments in SessionCallback’s constructor:

// Register PlayerCallback and make it to be called before the ListenableFuture set the result. // It help the PlayerCallback to update allowed commands before pended Player APIs are executed. sessionPlayerConnector.registerPlayerCallback(Runnable::run, new PlayerCallback());

At the time of the deadlock there were 2 registered SessionPlayer.PlayerCallback/Executor pairs, the one from the comment above, and the second being a MediaSessionImplBase.SessionPlayerCallback tied to the media session’s callback executor.

[REQUIRED] Link to test content

The issue isn’t media content-specific, but related to state handling and a concurrency issue.

[REQUIRED] A full bug report captured from the device

bugreport-sdk_gphone_x86_64-RSR1.200819.001.A1-2020-09-29-12-01-30.zip

Thread dump Thread dump

[REQUIRED] Version of ExoPlayer being used

2.12.0 (+ media2 extension)

[REQUIRED] Device(s) and version(s) of Android being used

This isn’t device or API-specific, reproduced and reported with an Android 11 (API30) emulator, (Image rev. 8, emulator v30.0.26) on a Windows 10 machine

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SungsooLimcommented, Dec 13, 2020

AndroidX media2 1.1.0 was release, and expect this issue is resolved in the next release of media2-extension.

0reactions
georgi-neykov-hubcommented, Dec 14, 2020

Thank you for the effort and support.

On Mon, Dec 14, 2020, 01:46 Sungsoo Lim notifications@github.com wrote:

AndroidX media2 1.1.0 was release, and expect this issue is resolved in the next release of media2-extension.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/ExoPlayer/issues/8011#issuecomment-744090339, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIFWVKZ3HQDIZMV2S4C743SUVG6FANCNFSM4R5QXEBQ .

Read more comments on GitHub >

github_iconTop Results From Across the Web

1.3 What is a Deadlock? (Sun Studio 12
Deadlock describes a condition in which two or more threads are blocked (hung) forever because they are waiting for each other. There are...
Read more >
The media2 extension for ExoPlayer | by Jaewan Kim - Medium
The ExoPlayer media2 extension provides SessionCallbackBuilder for building instances suitable for use with SessionPlayerConnector . When ...
Read more >
Room - Android Developers
The extension function RoomDatabase.withTransaction allows you to safely perform database transactions within a coroutine. Room extensions functions along with ...
Read more >
Debugging a Deadlock - Windows drivers | Microsoft Learn
A deadlock arises when two or more threads have requested locks on two ... This extension displays all the critical sections associated with...
Read more >
RELEASENOTES.md · master · Lahlouh, Ishak / RFC_Player
Make media2-extension depend on AndroidX media2:media2-session:1.1.0 to fix a deadlock while creating PlaybackStateCompat internally.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found