fix: realm+microsoft auth race that crashes mineflayer plugin injection - #1533
Open
DallasCarraher wants to merge 2 commits into
Open
DallasCarraher wants to merge 2 commits into
DallasCarraher wants to merge 2 commits into
Conversation
…g them via unhandled rejection
…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>
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
realmAuthenticate->authenticate) is async, soonReady()— which wires upregisterChannel/pluginChannelsamong other things — can still be pending whencreateClient()returns. mineflayer's plugin loader checksclient.wait_connectimmediately aftercreateClient()returns and, if it's falsy, injects plugins right away instead of waiting forconnect_allowed. That races ahead ofonReady()and crashes every realm+microsoft consumer withbot._client.registerChannel is not a functionbefore the device-code prompt even appears.wait_connectalready exists for exactly this kind of gating (seeautoVersion.js), it just wasn't set on the realm auth path. This sets it before the async chain starts and emitsconnect_allowedonceonReady()has actually run.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
realms.pickRealm) — previously crashed synchronously onbot._client.registerChannel is not a functionbefore any device-code prompt; now connects and proceeds into the configuration handshake normally.