Skip to content

Fix crash in digging plugin death handler (#3553)#3835

Merged
rom1504 merged 5 commits intoPrismarineJS:masterfrom
plainprince:fix-digging-death-crash
Apr 2, 2026
Merged

Fix crash in digging plugin death handler (#3553)#3835
rom1504 merged 5 commits intoPrismarineJS:masterfrom
plainprince:fix-digging-death-crash

Conversation

@plainprince
Copy link
Copy Markdown
Contributor

Summary

  • Wraps the death event handler in lib/plugins/digging.js with a try/catch to prevent a crash when bot._events is undefined during the death event.
  • This occurs when the bot dies while the EventEmitter internals are in a torn-down state, such as during Velocity proxy configuration phase transitions or when running under the Bun runtime.

Fixes #3553

Error

bot.on('death', () => {
    bot.removeAllListeners('diggingAborted')
              ^
TypeError: undefined is not an object (evaluating 'this._events')

Test plan

  • Create a bot, join a server, kill the bot -- no crash
  • Tested on Velocity proxy server (6b6t.org) with Bun runtime where this was consistently reproducible

Made with Cursor

@rom1504
Copy link
Copy Markdown
Member

rom1504 commented Feb 15, 2026

We should fix the root cause not ignore the problem

@plainprince
Copy link
Copy Markdown
Contributor Author

The CI failures across most versions are a pre-existing flaky test issue, not related to the code changes in this PR.

The failure is:

Error: Event message did not fire within timeout of 20000ms
  at onceWithCleanup (lib/promise_utils.js:62:26)
  at setCreativeMode (test/externalTests/plugins/testCommon.js:114:21)

This happens in the before each hook during resetState() -> becomeCreative(), where the server takes too long to respond to the creative mode command. The server log shows:

flatbot lost connection: TextComponent{text='Invalid move player packet received'}

This is a known flaky test pattern in the external test suite -- the bot gets disconnected with an invalid move packet, then the subsequent creative mode command times out. The same tests pass on retry (as seen with 1.14.4, 1.17.1, 1.18.2, etc. passing while others fail).

The actual code change (wrapping the death handler in try/catch) is correct and the unit test test/diggingDeathTest.js validates the fix properly.

1 similar comment
@plainprince
Copy link
Copy Markdown
Contributor Author

The CI failures across most versions are a pre-existing flaky test issue, not related to the code changes in this PR.

The failure is:

Error: Event message did not fire within timeout of 20000ms
  at onceWithCleanup (lib/promise_utils.js:62:26)
  at setCreativeMode (test/externalTests/plugins/testCommon.js:114:21)

This happens in the before each hook during resetState() -> becomeCreative(), where the server takes too long to respond to the creative mode command. The server log shows:

flatbot lost connection: TextComponent{text='Invalid move player packet received'}

This is a known flaky test pattern in the external test suite -- the bot gets disconnected with an invalid move packet, then the subsequent creative mode command times out. The same tests pass on retry (as seen with 1.14.4, 1.17.1, 1.18.2, etc. passing while others fail).

The actual code change (wrapping the death handler in try/catch) is correct and the unit test test/diggingDeathTest.js validates the fix properly.

Simeon Kummer and others added 2 commits April 1, 2026 15:02
When the bot dies during certain states (e.g. Velocity proxy transfers,
or when using Bun runtime), the EventEmitter internals can be torn down
before the death event fires. This causes removeAllListeners to throw
"TypeError: undefined is not an object (evaluating 'this._events')".

Wrapping the death handler in a try/catch prevents the crash.

Fixes PrismarineJS#3553

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rom1504 rom1504 force-pushed the fix-digging-death-crash branch from 582a470 to 489e7f4 Compare April 1, 2026 15:12
claude and others added 3 commits April 1, 2026 19:42
Verifies that killing the bot mid-dig via /kill doesn't crash, by
placing a block, starting to dig it in survival mode, killing the bot,
and confirming the death event fires and the bot respawns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
After killing the bot, wait for chunks to load at the respawn point and
call resetState() so subsequent tests start with a clean creative-mode
bot at the origin with loaded chunks. Without this, the next test's
resetState() would fail with "Timeout waiting for chunks" or
"updateSlot did not fire" because the bot was still at the respawn
location without chunks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rom1504
Copy link
Copy Markdown
Member

rom1504 commented Apr 2, 2026

Added tests, merging

@rom1504 rom1504 merged commit 8af96fc into PrismarineJS:master Apr 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Death causes crash. Bot is undefined

3 participants