Skip to content

fix(datapack): clear client registry on disconnect#72

Merged
duzos merged 3 commits into
mainfrom
fix/datapack-leak
Jun 5, 2026
Merged

fix(datapack): clear client registry on disconnect#72
duzos merged 3 commits into
mainfrom
fix/datapack-leak

Conversation

@duzos
Copy link
Copy Markdown
Contributor

@duzos duzos commented Jun 5, 2026

fixes #26

Server-synced datapack entries were leaking into the next world / singleplayer because the client registry was never cleared on disconnect and the cache clear in readFromServer was commented out. Clicking a leaked (server-only) entry in singleplayer crashed the game.

Changes in SimpleDatapackRegistry:

  • Register ClientPlayConnectionEvents.DISCONNECT in onClientInit() to clearCache() then re-apply defaults().
  • Un-comment this.clearCache() at the start of readFromServer so server data replaces cleanly instead of merging with leaked state.

Verified with ./gradlew compileJava (BUILD SUCCESSFUL).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a client-side datapack registry leak where server-synced entries persisted into subsequent singleplayer worlds, potentially causing crashes when interacting with server-only entries.

Changes:

  • Clear and reinitialize the client registry on disconnect via ClientPlayConnectionEvents.DISCONNECT.
  • Ensure server sync fully replaces client state by clearing the cache at the start of readFromServer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/dev/amble/lib/register/datapack/SimpleDatapackRegistry.java Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@duzos
Copy link
Copy Markdown
Contributor Author

duzos commented Jun 5, 2026

copilots latest review didnt post its thread (same github-mcp-server: Azure AI Agent request failed), noting it here - the concurrency comment was valid and is fixed in 52b3d9f:

  • the copied PacketByteBuf was never released (netty buffer leak) -> now released in a finally.
  • the deferred client.execute could run after a disconnect and repopulate the registry with stale server data -> now skips if client.getNetworkHandler() != handler.

./gradlew compileJava green.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@duzos duzos added A: Datapacks Area: SimpleDatapackRegistry and datapack-driven content. size/S Denotes a PR that changes 10-99 lines. T: Bugfix Type: Bugs and/or bugfixes. labels Jun 5, 2026
@duzos duzos merged commit d63308a into main Jun 5, 2026
2 checks passed
@duzos duzos deleted the fix/datapack-leak branch June 5, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A: Datapacks Area: SimpleDatapackRegistry and datapack-driven content. size/S Denotes a PR that changes 10-99 lines. T: Bugfix Type: Bugs and/or bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Datapacks from servers appear in singleplayer

2 participants