Skip to content

Commit be55f1a

Browse files
committed
fix: infinite loop in is_available_chunk when chunk groups form a cycle
1 parent cfe03e6 commit be55f1a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use indexmap::IndexSet;
77
use itertools::Itertools;
88
use rspack_cacheable::cacheable;
99
use rspack_collections::{DatabaseItem, IdentifierLinkedMap, IdentifierMap, IdentifierSet};
10+
use rspack_util::fx_hash::FxIndexSet;
1011
use rustc_hash::{FxHashMap as HashMap, FxHashSet};
1112
use serde::{Serialize, Serializer};
1213

@@ -916,8 +917,16 @@ impl ChunkGraph {
916917

917918
// true, if a is always a parent of b
918919
let is_available_chunk = |a: &Chunk, b: &Chunk| {
919-
let mut queue = b.groups().clone().into_iter().collect::<Vec<_>>();
920-
while let Some(chunk_group_ukey) = queue.pop() {
920+
let mut queue = b
921+
.groups()
922+
.clone()
923+
.into_iter()
924+
.collect::<FxIndexSet<ChunkGroupUkey>>();
925+
let mut index: usize = 0;
926+
while index < queue.len() {
927+
let chunk_group_ukey = queue[index];
928+
index += 1;
929+
921930
if a.is_in_group(&chunk_group_ukey) {
922931
continue;
923932
}
@@ -926,7 +935,7 @@ impl ChunkGraph {
926935
return false;
927936
}
928937
for parent in chunk_group.parents_iterable() {
929-
queue.push(*parent);
938+
queue.insert(*parent);
930939
}
931940
}
932941
true

0 commit comments

Comments
 (0)