Skip to content

Don't crash the agent if prismarine-viewer can't bind its port#760

Draft
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
domdomegg:viewer-crash-isolation
Draft

Don't crash the agent if prismarine-viewer can't bind its port#760
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
domdomegg:viewer-crash-isolation

Conversation

@domdomegg
Copy link
Copy Markdown

@domdomegg domdomegg commented Apr 15, 2026

When render_bot_view: true, prismarine-viewer's mineflayer() starts an http server on port 3000 + count_id. It doesn't expose the server object, so if the port is already in use the EADDRINUSE becomes an uncaught exception and the whole agent process dies.

Repro: have anything listening on :3000 (e.g. another dev server), set render_bot_view: true, start an agent → crash on spawn.

Since the server isn't returned, this hooks http.createServer for the duration of the mineflayer() 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 a finally so it's only in place for that one synchronous call. There's also a try/catch for anything that throws synchronously during init.

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.
@domdomegg domdomegg force-pushed the viewer-crash-isolation branch from 0272605 to 9329fe0 Compare April 15, 2026 15:28
@domdomegg
Copy link
Copy Markdown
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)

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