fix(recording): reschedule packet send recording onto server thread#45
Merged
JustinDevB merged 1 commit intoMay 1, 2026
Merged
Conversation
Issue JustinDevB#43 reported a Netty packet-send thread blocked in HashMap.put while BetterReplay was recording block break animations. The packet callback was doing Bukkit lookups and mutating shared recording state directly from PacketEvents' send listener, which meant Netty could touch the block-break dedup map, timeline builder, entity tracking, and append-log path off the server thread. Capture the packet data immediately, then hand the recording work back to the server thread through FoliaLib before reading Bukkit state or mutating recording structures. This keeps the PacketEvents callback narrow and removes the cross-thread mutation hazard that could stall shutdown and contend inside HashMap tree insertion. Add regression coverage for the main-thread handoff and for tracked-viewer block break stage recording, and document the fix in the changelog. Validation: runTests passed for RecordingPacketHandlerTest and the full suite passed with 481 tests green. Refs: JustinDevB#43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
Issue #43 reported a Netty packet-send thread blocked in
HashMap.putwhile BetterReplay was recording block break animations.Before this change, the PacketEvents send listener handled more than packet decoding. It also performed Bukkit lookups and mutated shared recording state directly from the packet callback. That meant a Netty thread could touch:
That is the wrong thread boundary for both Bukkit access and BetterReplay's recording session state.
Fix
The packet listener now copies the minimal block break animation data it needs immediately, then reschedules the actual recording work onto the server thread through FoliaLib. Bukkit lookups, dedup mutation, and timeline event emission all happen on the server thread again.
This keeps the packet callback small and removes the cross-thread mutation hazard that was behind issue #43.
Validation
runTestspassed forRecordingPacketHandlerTestRefs #43