mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
We've had some really bad bugs in the past, which can be hard to root-cause due to eventually-consistent reads a the top-level, e.g. https://github.com/vercel/next.js/pull/77511 Outside of tests, there's no good justification for doing an eventually-consistent read at the top level. It may leak incomplete computations, which can contain errors that would otherwise be resolved by a strongly consistent read. The basic idea here is simple: - Store a flag in `CURRENT_TASK_STATE` indicating that we're in a top-level task. - When reading a task output or cell, check for that flag. But, there are a few complications: - `RawVc`'s read and resolution logic is wrong, and internally uses multiple eventually consistent operations after a strongly consistent read. - For this to be correct, it needs to happen as one atomic operation inside of the task backend, but it would change the backend API contract, so it's not straightforward to do that. - I added a `SUPPRESS_EVENTUAL_CONSISTENCY_TOP_LEVEL_TASK_CHECK` flag that I'm using for now. - There are a ton of places that are doing eventually consistent reads for no good reason. These aren't causing problems today, but we should fix them instead of suppressing them. Claude helped with this, but it's still a lot. - Some tests actually do need eventually-consistent reads because they're testing some internal behavior of turbo-tasks. I added an intentionally long-named `unmark_top_level_task_may_leak_eventually_consistent_state` helper for this. I manually tested `turbopack-cli` against our bundler-benchmark repository that uses it.
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this
|
|
|
|
use anyhow::Result;
|
|
use turbo_rcstr::RcStr;
|
|
use turbo_tasks::{Vc, debug::ValueDebugFormat};
|
|
use turbo_tasks_testing::{Registration, register, run_once};
|
|
|
|
static REGISTRATION: Registration = register!();
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn ignored_indexes() {
|
|
#[allow(dead_code)]
|
|
#[derive(ValueDebugFormat)]
|
|
struct IgnoredIndexes(
|
|
#[allow(dead_code)]
|
|
#[turbo_tasks(debug_ignore)]
|
|
i32,
|
|
i32,
|
|
#[allow(dead_code)]
|
|
#[turbo_tasks(debug_ignore)]
|
|
i32,
|
|
);
|
|
|
|
run_once(®ISTRATION, || async {
|
|
#[turbo_tasks::function(operation)]
|
|
async fn value_debug_format_operation() -> Result<Vc<RcStr>> {
|
|
let input = IgnoredIndexes(-1, 2, -3);
|
|
let debug = input.value_debug_format(usize::MAX).try_to_string().await?;
|
|
Ok(Vc::cell(RcStr::from(debug)))
|
|
}
|
|
let debug = value_debug_format_operation()
|
|
.read_strongly_consistent()
|
|
.await?;
|
|
assert!(!debug.contains("-1"));
|
|
assert!(debug.contains('2'));
|
|
assert!(!debug.contains("-3"));
|
|
anyhow::Ok(())
|
|
})
|
|
.await
|
|
.unwrap();
|
|
}
|