Don't crash the agent if prismarine-viewer can't bind its port#760
Draft
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
Draft
Don't crash the agent if prismarine-viewer can't bind its port#760domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
Conversation
mineflayerViewer() creates an http server on 3000+count_id but doesn't expose it, so EADDRINUSE (e.g. something already on :3000, or two agents racing) becomes an uncaught exception that kills the agent process. Probe the port first and fall back to a warning + no viewer.
0272605 to
9329fe0
Compare
Author
|
Leaving this as draft as unsure what the preferred behaviour is here. I think this is better but can see how erroring more loudly could be preferred, or the implementation seen as too hacky (probably should actually upstream better error handling in prismarine-viewer) |
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.
When
render_bot_view: true,prismarine-viewer'smineflayer()starts an http server on port3000 + count_id. It doesn't expose the server object, so if the port is already in use theEADDRINUSEbecomes an uncaught exception and the whole agent process dies.Repro: have anything listening on
:3000(e.g. another dev server), setrender_bot_view: true, start an agent → crash on spawn.Since the server isn't returned, this hooks
http.createServerfor the duration of themineflayer()call to attach an'error'listener to whatever server it makes. Bind failures then log a warning and the agent continues without a viewer. The hook is restored in afinallyso it's only in place for that one synchronous call. There's also a try/catch for anything that throws synchronously during init.