-
Notifications
You must be signed in to change notification settings - Fork 29
Description
What happened?
Hello BCLib Team,
I've been experiencing some recurring server freezes on my heavily modded 1.20.1 server. After some investigation, the evidence seems to point towards a possible issue within BCLib, and I wanted to share my findings in case they're helpful.
Symptoms
My server's main thread will hang, becoming unresponsive until the watchdog timer terminates the process. The crash report's stack trace is very consistent and always points to the same isShears handler within Minecraft's ItemPredicate class.
java.lang.Error: Watchdog
at knot//com.google.common.collect.SingletonImmutableSet.contains(SingletonImmutableSet.java:50)
at knot//net.minecraft.class_2073.handler$bbf001$bclib$isShears(class_2073.java:1028)
Possible Cause & Analysis
Looking at the code, I believe the issue might be located in MatchToolMixin.java (org.betterx.bclib.mixin.common.shears.MatchToolMixin).
The mixin's purpose appears to be expanding the vanilla minecraft:shears predicate to also match the c:shears item tag for better mod compatibility, which is a fantastic feature.
However, I have a theory that the constructor in the mixin might not fully account for predicates that are defined by a tag instead of a specific list of items. I suspect that when the mixin encounters a predicate checking for an item tag (for example, #c:shears), its attempt to access the item list could be triggering a recursive lookup, leading to the server freeze.
Suggested Change for Consideration
Based on this theory, a potential fix might involve making the check in the constructor safer. An approach could be to first verify that the predicate is defined by an item list before attempting to read its contents.
Here is an example of what that might look like, though please note this code is untested and is only meant to illustrate the idea:
File: src/main/java/org/betterx/bclib/mixin/common/shears/MatchToolMixin.java
// ...
import net.minecraft.world.item.Items;
import java.util.Optional;
// ...
@Inject(method = "<init>", at = @At("TAIL"))
private void bcl_initShears(Optional<ItemPredicate> optional, CallbackInfo ci) {
if (optional.isPresent()) {
final ItemPredicate predicate = optional.get();
// Suggested change:
// First, safely check if the predicate is based on an item list.
// Only then, attempt to get and check the contents of that list.
if (predicate.items().isPresent()) {
final var items = predicate.items().get();
if (items.size() == 1 && items.stream().findFirst().get().value() == Items.SHEARS) {
bcl_isShears = true;
}
}
}
}
// ...Again, this is just a hypothetical fix based on my analysis of the code. The goal would be to add a guard clause to prevent the mixin from causing a hang when it encounters tag-based predicates.
I hope this information is useful and helps you diagnose and address the potential issue. Thanks for all your hard work on this library!
BCLib
3.0.14
WorldWeaver
not using?
Fabric API
0.92.6+1.20.1
Fabric Loader
0.16.14
Minecraft
1.20.1