Skip to content

fix: realm+microsoft auth race that crashes mineflayer plugin injection - #1533

Open
DallasCarraher wants to merge 2 commits into
PrismarineJS:masterfrom
DallasCarraher:fix-realm-wait-connect
Open

DallasCarraher wants to merge 2 commits into
PrismarineJS:masterfrom
DallasCarraher:fix-realm-wait-connect

Conversation

@DallasCarraher

Copy link
Copy Markdown

Summary

  • Realm auth (realmAuthenticate -> authenticate) is async, so onReady() — which wires up registerChannel/pluginChannels among other things — can still be pending when createClient() returns. mineflayer's plugin loader checks client.wait_connect immediately after createClient() returns and, if it's falsy, injects plugins right away instead of waiting for connect_allowed. That races ahead of onReady() and crashes every realm+microsoft consumer with bot._client.registerChannel is not a function before the device-code prompt even appears.
  • wait_connect already exists for exactly this kind of gating (see autoVersion.js), it just wasn't set on the realm auth path. This sets it before the async chain starts and emits connect_allowed once onReady() has actually run.
  • Also includes an earlier, related commit from this branch (surfacing setup errors via client.emit('error', ...) instead of letting them become an unhandled rejection) since it's what made this race visible/debuggable in the first place rather than failing silently.

Test plan

  • Live-tested against a real Realm connection (Microsoft auth, realms.pickRealm) — previously crashed synchronously on bot._client.registerChannel is not a function before any device-code prompt; now connects and proceeds into the configuration handshake normally.
  • No existing test in this repo's suite exercises the realm+microsoft path directly (it requires live Microsoft/Realms auth), so this is verified via live connection rather than an added unit test.

DallasCarraher and others added 2 commits September 15, 2026 23:52
…njected early

Realm auth (realmAuthenticate -> authenticate) is async, so onReady()
— which wires up registerChannel/pluginChannels among other things —
can still be pending when createClient() returns. mineflayer's plugin
loader checks client.wait_connect immediately after createClient()
returns and, if it's falsy, injects plugins right away instead of
waiting for 'connect_allowed'. That races ahead of onReady() and
crashes every realm+microsoft consumer with "bot._client.registerChannel
is not a function" before the device-code prompt even appears.

wait_connect already exists for exactly this kind of gating (see
autoVersion.js), just wasn't set on this path. Set it before the async
chain starts and emit connect_allowed once onReady() has actually run.

Found live-testing a realm connection against a 26.3 server with
mineflayer.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant