Avoid racing issue when play/stop and reinit or destroy stream at the same time
Categories
(Core :: Audio/Video: cubeb, defect, P2)
Tracking
()
People
(Reporter: chunmin, Assigned: chunmin)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 obsolete file)
The Rust AudioUnit backend has no way to prevent the stream is played or stopped when the stream is being reinitialized or destroyed, while C backend uses a mutex to prevent this problem.
| Assignee | ||
Comment 1•6 years ago
•
|
||
Several racing issues:
- If
cubeb_stream_startandcubeb_stream_destroyrun in parallel, then the cubeb stream may start playing while it's being destroyed.cubeb_stream_startcan be called after stopping the running callback indestroyhere
- If
cubeb_stream_stopandcubeb_stream_destroyrun in parallel, then the cubeb stream may stop twice (but it‘s probably harmless). - If
cubeb_stream_startandreinitrun in parallel, then cubeb stream may start playing while it's being reinitialized.cubeb_stream_startcan be called after checkingself.shutdown.load(Ordering::SeqCst)inreinithere
- If
cubeb_stream_stopandreinitrun in parallel, then cubeb stream may not stop successfullycubeb_stream_stopcan be called after checkingself.shutdown.load(Ordering::SeqCst)inreinithere.
- If
cubeb_stream_destroyandreinitrun in parallel, then the running callback may not be stopped while it's being destroyed.
These could be tested by the manual test added in https://github.com/ChunMinChang/cubeb-coreaudio-rs/pull/24/commits/148e57510bddb589b689852f8843be126dc0b675 , with some thread-sleep added
For 1 and 2, they could be avoided if cubeb_stream_start, cubeb_stream_stop and cubeb_stream_destroy are run in the same task queue in gecko. For 3, 4, 5, we need to fix those in the Rust backend.
| Assignee | ||
Comment 2•6 years ago
|
||
(In reply to C.M.Chang[:chunmin] from comment #1)
I didn't notice the start or stop may run in parallel with reinit or destroy when defusing the custom mutex (OwnedCriticalSection). The quickest way to fix these may use a Mutex around core_stream_data (revert this).
| Assignee | ||
Comment 3•6 years ago
|
||
(In reply to C.M.Chang[:chunmin] from comment #2)
(In reply to C.M.Chang[:chunmin] from comment #1)
... fix these may use aMutexaroundcore_stream_data(revert this).
I changed my mind. This will cause the deadlocks when data-callback thread try to lock core_stream_data in input/output data callback while holding the mutex inside AudioUnit and destory/reinit thread try to call stream-stop that tries to lock the mutex inside AudioUnit while holding the mutex around core_stream_data.
Dispatching stream-start/stop work to the task queue where destroy and reinit are is probably an easier solution. So stream-start/stop, destroy and reinit are all run in the same task queue.
| Assignee | ||
Comment 4•6 years ago
|
||
| Assignee | ||
Comment 5•6 years ago
|
||
Pick commits:
b6d5b75 - Avoid various racing issues (#26)
dba0344 - Add manual tests (#24)
| Assignee | ||
Updated•6 years ago
|
| Assignee | ||
Updated•6 years ago
|
Updated•6 years ago
|
| Assignee | ||
Comment 6•6 years ago
|
||
D56160 in bug 1601859 imports the #PR 26 (Attachment 9111456 [details])
Description
•