Crash in AQClient when calling -[AVAssetReader cancelReading]

Originator:chad515
Number:rdar://15134003 Date Originated:10/02/2013
Status:Duplicate Resolved:No
Product:OS X SDK Product Version:10.8.5
Classification:Crash Reproducible:Sometimes
 
Summary:
A crash can occur when using AVFoundation's AVAssetReader and attempting to cancel reading. This seems to occur most often when the cancelReading call occurs soon after startReading is called. The crash does not occur every time, and appears to expose a race condition. The crash always occurs on an AQClient thread, while another thread is calling cancelReading.

Steps to Reproduce:
1. Create an AVURLAsset for a media file. It's possible that the bug occurs more frequently when the file is on a slower drive, but I've seen it occur when on a fast SSD as well.
2. Create and AVAssetReader with the file.
3. Create an AVAssetReaderTrackOutput with one of the audio tracks from the asset (e.g. the first track).
4. Add that as an output to the asset reader.
5. Call startReading on the asset reader.
6. Call cancelReading on the asset reader.

Perform the above steps repeatedly until the crash is triggered. I find that if I run 4 threads in tight loops doing this, the crash will always present itself. It may take a few seconds or a few hours, but it will present.



Expected Results:
No crash

Actual Results:
Crash

Version:
Xcode 4 and 5
OS X 10.8 at various point releases (most recently 10.8.5/12F37)

Notes:
I've found I can workaround this by introducing a .2 second delay before calling cancelReading. This seems to generally be enough time for the reader to finish spinning up to avoid the race.

Comments

Duplicate

Closed as duplicate of rdar://11577119


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!