Fix MediaHTTPConnection.disconnect() blocking for a long time.
MediaHTTPConnection.seek() was creating new connections in a while loop without checking whether another thread was busy concurrently disconnecting. When a new connection was created between the time the disconnect()ing thread had disconnected the old one and acquired the synchronized block, the new connection wouldn't be disconnected and therefore seek() would not encounter an IOException; therefore, seek() would not return quickly, leaving the disconnecting thread waiting to acquire the synchronized block for a long time. This CL fixes this by making seek() throw IOException quickly if it discovers that another thread is trying to disconnect. This is checked shortly before and after the new connection is created, to avoid a race based on the order between the new connection being created and the disconnecting thread reading the old connection value. Note that this still doesn't stop a new connection being created shortly after the previous one was torn down - it only stops the disconnecting thread waiting for a long time to acquire the synchronized lock. Fixes: 131894499 Test: The following command hang 3/3 times before this CL, but succeeded 3/3 times afterwards: atest android.media.cts.NativeDecoderTest#testAMediaDataSourceClose Change-Id: I3862a4367d0e46c64c0cbf7bcaa369aca5692871
Loading
Please register or sign in to comment