Fix race condition from not releasing Mutex guard and Arc ref on async JS min jobs

This commit is contained in:
Wilson Lin 2020-07-22 21:33:52 +10:00
parent cc98a61bc2
commit e1e18bb1a7
1 changed files with 6 additions and 1 deletions

View File

@ -40,10 +40,15 @@ pub fn process_script(proc: &mut Processor, cfg: &Cfg) -> ProcessingResult<()> {
let src = start.written_range(proc);
// TODO Optimise: Avoid copying to new Vec.
esbuild_rs::transform(Arc::new(proc[src].to_vec()), TRANSFORM_OPTIONS.clone(), move |result| {
results.lock().unwrap().push(JsMinSection {
let mut guard = results.lock().unwrap();
guard.push(JsMinSection {
src,
result,
});
// Drop Arc reference and Mutex guard before marking task as complete as it's possible proc::finish
// waiting on WaitGroup will resume before Arc/Mutex is dropped after exiting this function.
drop(guard);
drop(results);
drop(wg);
});
return Ok(());