Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1ae37202
Commit
1ae37202
authored
Mar 01, 2026
by
Tobias Koppers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flush() safety docs and make parallel flush sequential to prevent UB
parent
fc5689a8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
14 deletions
+16
-14
write_batch.rs
turbopack/crates/turbo-persistence/src/write_batch.rs
+3
-2
write_batch.rs
...ck/crates/turbo-tasks-backend/src/database/write_batch.rs
+5
-2
kv_backing_storage.rs
...pack/crates/turbo-tasks-backend/src/kv_backing_storage.rs
+8
-10
No files found.
turbopack/crates/turbo-persistence/src/write_batch.rs
View file @
1ae37202
...
...
@@ -238,8 +238,9 @@ impl<K: StoreKey + Send + Sync, S: ParallelScheduler, const FAMILIES: usize>
///
/// # Safety
///
/// Caller must ensure that no concurrent put or delete operation is happening on the flushed
/// family.
/// Caller must ensure that no concurrent `put` or `delete` operation is happening on *any*
/// family (not just the flushed one), because the implementation accesses thread-local state
/// that spans all families. Concurrent flushes of different families are also not allowed.
#[tracing
::
instrument(level
=
"trace"
,
skip(self))]
pub
unsafe
fn
flush
(
&
self
,
family
:
u32
)
->
Result
<
()
>
{
// Flush the thread local collectors to the global collector.
...
...
turbopack/crates/turbo-tasks-backend/src/database/write_batch.rs
View file @
1ae37202
...
...
@@ -75,8 +75,11 @@ pub trait ConcurrentWriteBatch<'a>: BaseWriteBatch<'a> + Sync + Send {
/// Flushes a key space of the write batch, reducing the amount of buffered memory used.
/// Does not commit any data persistently.
///
/// Safety: Caller must ensure that no concurrent put or delete operation is happening on the
/// flushed key space.
/// # Safety
///
/// Caller must ensure that no concurrent `put` or `delete` operation is happening on *any*
/// key space (not just the flushed one), because implementations may access shared state
/// spanning all key spaces. Concurrent flushes of different key spaces are also not allowed.
unsafe
fn
flush
(
&
self
,
key_space
:
KeySpace
)
->
Result
<
()
>
;
}
...
...
turbopack/crates/turbo-tasks-backend/src/kv_backing_storage.rs
View file @
1ae37202
...
...
@@ -283,16 +283,14 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
{
let
_span
=
tracing
::
trace_span!
(
"update task data"
)
.entered
();
process_task_data
(
snapshots
,
Some
(
batch
))
?
;
let
span
=
tracing
::
trace_span!
(
"flush task data"
)
.entered
();
parallel
::
try_for_each
(
&
[
KeySpace
::
TaskMeta
,
KeySpace
::
TaskData
],
|
&
key_space
|
{
let
_span
=
span
.clone
()
.entered
();
// Safety: We already finished all processing of the task data and task
// meta
unsafe
{
batch
.flush
(
key_space
)
}
},
)
?
;
let
_span
=
tracing
::
trace_span!
(
"flush task data"
)
.entered
();
// Flush sequentially: flush() accesses per-thread state covering all
// families, so concurrent flushes of different key spaces would be UB.
for
&
key_space
in
&
[
KeySpace
::
TaskMeta
,
KeySpace
::
TaskData
]
{
// Safety: process_task_data has completed; no concurrent put/delete
// on any key space.
unsafe
{
batch
.flush
(
key_space
)
}
?
;
}
}
let
mut
next_task_id
=
get_next_free_task_id
::
<
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment