-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix static file paths and race conditions (#473)
* fix: Use entrypoint path as static file root when available. * fix(graph): don't spawn tasks in the current runtime * fix: fmt * stamp: typing * stamp(graph): use semaphore to ensure strong count is exactly one --------- Co-authored-by: Nyannyacha <[email protected]>
- Loading branch information
1 parent
8989dd3
commit 085c61e
Showing
9 changed files
with
65 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
use once_cell::sync::Lazy; | ||
|
||
pub(crate) static SYNC_IO_RT: Lazy<tokio::runtime::Runtime> = Lazy::new(|| { | ||
pub static IO_RT: Lazy<tokio::runtime::Runtime> = Lazy::new(|| { | ||
tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.thread_name("sb-virtualfs-io") | ||
.thread_name("io") | ||
.build() | ||
.unwrap() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ use std::fs::{create_dir_all, File}; | |
use std::io::{Cursor, SeekFrom, Write}; | ||
use std::path::{Path, PathBuf}; | ||
use std::sync::Arc; | ||
use tokio::sync::Mutex; | ||
use tokio::sync::{Mutex, Semaphore}; | ||
|
||
mod eszip_parse; | ||
|
||
|
@@ -44,6 +44,8 @@ pub mod resolver; | |
|
||
pub use eszip::v2::Checksum; | ||
|
||
const READ_ALL_BARRIER_MAX_PERMITS: usize = 10; | ||
|
||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum DecoratorType { | ||
|
@@ -158,14 +160,20 @@ impl LazyLoadableEszip { | |
|
||
if let Some(section) = self.maybe_data_section.clone() { | ||
let specifier = module.specifier.clone(); | ||
let sem = section.read_all_barrier.clone(); | ||
|
||
drop(fs::IO_RT.spawn(async move { | ||
let permit = sem.acquire_owned().await.unwrap(); | ||
|
||
drop(tokio::spawn(async move { | ||
match section.read_data_section_by_specifier(&specifier).await { | ||
Ok(_) => {} | ||
Err(err) => { | ||
error!("failed to read module data from the data section: {}", err); | ||
} | ||
} | ||
|
||
drop(section); | ||
drop(permit); | ||
})); | ||
} | ||
|
||
|
@@ -222,6 +230,7 @@ pub struct EszipDataSection { | |
sources_len: Arc<Mutex<Option<u64>>>, | ||
locs_by_specifier: Arc<Mutex<Option<HashMap<String, EszipDataSectionMetadata>>>>, | ||
loaded_locs_by_specifier: Arc<Mutex<HashMap<String, EszipDataLoc>>>, | ||
read_all_barrier: Arc<Semaphore>, | ||
} | ||
|
||
impl EszipDataSection { | ||
|
@@ -239,6 +248,7 @@ impl EszipDataSection { | |
sources_len: Arc::default(), | ||
locs_by_specifier: Arc::default(), | ||
loaded_locs_by_specifier: Arc::default(), | ||
read_all_barrier: Arc::new(Semaphore::new(READ_ALL_BARRIER_MAX_PERMITS)), | ||
} | ||
} | ||
|
||
|
@@ -408,7 +418,20 @@ impl EszipDataSection { | |
pub async fn read_data_section_all(self: Arc<Self>) -> Result<(), ParseError> { | ||
// NOTE: Below codes is roughly originated from [email protected]/src/v2.rs | ||
|
||
let this = Arc::into_inner(self).unwrap(); | ||
let this = { | ||
let sem = self.read_all_barrier.clone(); | ||
let permit = sem | ||
.acquire_many(READ_ALL_BARRIER_MAX_PERMITS as u32) | ||
.await | ||
.unwrap(); | ||
|
||
let this = Arc::into_inner(self).unwrap(); | ||
|
||
sem.close(); | ||
drop(permit); | ||
this | ||
}; | ||
|
||
let modules = this.modules; | ||
let checksum_size = this | ||
.options | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { join } from 'https://deno.land/std/path/mod.ts'; | ||
|
||
Deno.serve(async (req) => { | ||
if (req.url.endsWith('/foo')) { | ||
return new Response(await Deno.readTextFile(join(import.meta.dirname, 'foo.html'))); | ||
} else { | ||
return new Response(await Deno.readTextFile(join(import.meta.dirname, 'bar.html'))); | ||
} | ||
if (req.url.endsWith('/foo')) { | ||
return new Response(await Deno.readTextFile(new URL('./foo.html', import.meta.url))); | ||
} else { | ||
return new Response(await Deno.readTextFile(new URL('./bar.html', import.meta.url))); | ||
} | ||
}); |