diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 1c49983d54db855297db8fb2d37d6d560a8116d8..b519265a9d6f54a47e210d4672e87a22f588a29d 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -442,7 +442,15 @@ pub const Node = struct { global_progress.ipc_files[slot] = file; storageByIndex(index).setIpcIndex(.{ .slot = slot, .generation = generation }); break; - } else file.close(io); + } else { + // There was no IPC slot available, so we'll drop this node's IPC info and just close + // the fd. To avoid an old `estimated_total_items` or `completed_count` value still + // being rendered for the node, we'll zero that field out (and the user is not allowed + // to change it because they think we're doing IPC). + file.close(io); + @atomicStore(u32, &storageByIndex(index).completed_count, 0, .monotonic); + @atomicStore(u32, &storageByIndex(index).estimated_total_count, 0, .monotonic); + } } pub fn setIpcIndex(node: Node, ipc_index: Ipc.Index) void { @@ -452,7 +460,11 @@ pub const Node = struct { /// Not thread-safe. pub fn takeIpcIndex(node: Node) ?Ipc.Index { const storage = storageByIndex(node.index.unwrap() orelse return null); - assert(storage.estimated_total_count == std.math.maxInt(u32)); + switch (storage.estimated_total_count) { + std.math.maxInt(u32) => {}, // indicates that there is an IPC index in `completed_count` + 0 => return null, // `setIpcFile` failed so we don't have an IPC index for this node + else => unreachable, // not an IPC node + } @atomicStore(u32, &storage.estimated_total_count, 0, .monotonic); return @bitCast(storage.completed_count); }