Unverified Commit 3de15d2b authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Cover state initialization and snapshot helpers on canary

Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 69251f99
...@@ -386,7 +386,7 @@ impl TurboTasksBackend { ...@@ -386,7 +386,7 @@ impl TurboTasksBackend {
// State slots owned by collected tasks disappeared from the state map. // State slots owned by collected tasks disappeared from the state map.
// Drop surviving readers' forward edges before dirtying, just like // Drop surviving readers' forward edges before dirtying, just like
// reverse cell edges in CleanupOldEdgesOperation. // reverse cell edges in cleanup_old_edges.
let removed_states = std::mem::take(&mut result.deleted_state_dependents); let removed_states = std::mem::take(&mut result.deleted_state_dependents);
if !removed_states.is_empty() { if !removed_states.is_empty() {
let noop_collector = |_task_id| {}; let noop_collector = |_task_id| {};
......
...@@ -3949,8 +3949,8 @@ impl Backend for TurboTasksBackend { ...@@ -3949,8 +3949,8 @@ impl Backend for TurboTasksBackend {
if entry.value == value { if entry.value == value {
return Ok(false); return Ok(false);
} }
// Dirtying and publication share one operation guard. Canary snapshots // Dirtying and publication share one operation guard. Snapshots wait
// wait for graph operations to settle before closing admission. // for active operations to settle before closing admission.
let _scope = StateMutationScope::enter(); let _scope = StateMutationScope::enter();
let mut queue = AggregationUpdateQueue::new(); let mut queue = AggregationUpdateQueue::new();
for &reader in &entry.dependents { for &reader in &entry.dependents {
......
...@@ -1888,7 +1888,7 @@ mod must_exist_tests { ...@@ -1888,7 +1888,7 @@ mod must_exist_tests {
task_type_hash: None, task_type_hash: None,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
backing.save_snapshot(None, vec![items]).unwrap(); backing.save_snapshot(None, vec![items], None).unwrap();
let tt = TurboTasks::new(TurboTasksBackend::new( let tt = TurboTasks::new(TurboTasksBackend::new(
BackendOptions { BackendOptions {
storage_mode: Some(StorageMode::ReadOnly), storage_mode: Some(StorageMode::ReadOnly),
......
...@@ -123,6 +123,52 @@ fn untracked_reader(counter: TurboTasksState<u32>) -> Vc<Number> { ...@@ -123,6 +123,52 @@ fn untracked_reader(counter: TurboTasksState<u32>) -> Vc<Number> {
Number(counter.get_untracked()).cell() Number(counter.get_untracked()).cell()
} }
#[cfg(debug_assertions)]
#[turbo_tasks::state]
static REENTRANT_INITIALIZER: StateSlot<ReentrantInitializer> = StateSlot::new();
#[cfg(debug_assertions)]
#[derive(bincode::Decode)]
struct ReentrantInitializer(bool);
#[cfg(debug_assertions)]
impl bincode::Encode for ReentrantInitializer {
fn encode<E: bincode::enc::Encoder>(
&self,
encoder: &mut E,
) -> Result<(), bincode::error::EncodeError> {
if self.0 {
let _root = StateOwnerRoot::named("reentrant-state-codec".into());
}
bincode::Encode::encode(&self.0, encoder)
}
}
#[cfg(debug_assertions)]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn state_initializer_reentrancy_is_rejected_and_store_recovers() {
run_without_cache_check(&REGISTRATION, async {
let root = StateOwnerRoot::named("initializer-reentrancy".into());
let panic = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
REENTRANT_INITIALIZER.for_named_owner(&root, ReentrantInitializer(true));
}))
.expect_err("reentrant serializer was not rejected");
let message = panic
.downcast_ref::<String>()
.map(String::as_str)
.or_else(|| panic.downcast_ref::<&str>().copied())
.expect("panic did not contain a message");
assert!(message.contains("must not call back into turbo-tasks"));
// The vacant entry and mutation scope must unwind without poisoning
// the canonical store or leaving the snapshot operation active.
let state = REENTRANT_INITIALIZER.for_named_owner(&root, ReentrantInitializer(false));
assert!(!state.get_untracked().0);
anyhow::Ok(())
})
.await
.unwrap();
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn existing_state_does_not_serialize_unused_initializer() { async fn existing_state_does_not_serialize_unused_initializer() {
run_without_cache_check(&REGISTRATION, async { run_without_cache_check(&REGISTRATION, async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment