Skip to content

Commit

Permalink
Revert "Fix potential ThreadPool UAF (#113)"
Browse files Browse the repository at this point in the history
This reverts commit dbe2291, reversing
changes made to 43c7e4b.
  • Loading branch information
mitchellh committed Nov 4, 2024
1 parent d46619a commit 6afcde9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ThreadPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,12 @@ fn unregister(noalias self: *ThreadPool, noalias maybe_thread: ?*Thread) void {

fn join(self: *ThreadPool) void {
// Wait for the thread pool to be shutdown() then for all threads to enter a joinable state
self.join_event.wait();
const sync: Sync = @bitCast(self.sync.load(.monotonic));
var sync: Sync = @bitCast(self.sync.load(.monotonic));
if (!(sync.state == .shutdown and sync.spawned == 0)) {
self.join_event.wait();
sync = @bitCast(self.sync.load(.monotonic));
}

assert(sync.state == .shutdown);
assert(sync.spawned == 0);

Expand Down

1 comment on commit 6afcde9

@mitchellh
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kprotty I hate introducing a UAF in real code but this fixes our tests. Given this only happens in deinit which generally only happens on process exit, I'm okay with this until I can dig in and see how to fix this more robustly. Sorry!

Please sign in to comment.