-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix std.Progress panic #23662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix std.Progress panic #23662
Conversation
Prevents a crash in serialize() when there are many threads trying to call Node.start() at the same time.
Node.init() failed an assert, indicating that we were attempting to use a node slot that was already in use. This was caused by an ABA problem involving node_freelist_first. Fixed by making node_freelist_first into a generational index.
@@ -307,7 +307,8 @@ pub const Node = struct { | |||
@atomicStore(u8, &storage.name[name_len], 0, .monotonic); | |||
|
|||
const parent_ptr = parentByIndex(free_index); | |||
assert(parent_ptr.* == .unused); | |||
const current_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In non-safe builds this introduces an unnecessary acquire-load. Not sure what to do about that.
@@ -246,7 +246,7 @@ pub const Node = struct { | |||
} | |||
const index = n.index.unwrap() orelse return; | |||
const parent_ptr = parentByIndex(index); | |||
if (parent_ptr.unwrap()) |parent_index| { | |||
if (@atomicLoad(Parent, parent_ptr, .acquire).unwrap()) |parent_index| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the acquire-load to match the other acquire-load of parentByIndex()
in Node.init()
. I think it makes sense, but tbh I'm not 100% sure it's necessary.
.opt_index = @intFromEnum(OptionalIndex.none), | ||
}; | ||
|
||
fn unwrap_index(i: @This()) ?Index { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function names in Zig are camel case
Superseded by #23725; thanks for the work here @achan1989! |
Fixes #21663
The main issue was an ABA problem in the maintenance of the freelist. This has been fixed by making
node_freelist_first
into a generational index.Also in this MR are fixes for some other issues I encountered while investigating this.
An example program to reproduce the issue and confirm the fix.
Run like
repro 20 3
to reproduce the main issue. Run likerepro 200 3
to reproduce the issue behind commit "Fix maintenance of node_end_index when out of node storage memory".