fix: improve connection stability for Paper/Spigot servers#704
fix: improve connection stability for Paper/Spigot servers#704atiweb wants to merge 2 commits intomindcraft-bots:developfrom
Conversation
Add two targeted fixes for Paper server compatibility: 1. Position packet throttling (50ms minimum interval) Paper enforces stricter packet rate limits than vanilla Minecraft. When mineflayer sends position/look packets faster than ~50ms, Paper kicks the client with ECONNRESET. This throttles outgoing position packets to stay under the limit. 2. PartialReadError suppression for non-critical packets Paper servers sometimes send packets that node-minecraft-protocol cannot fully parse (scoreboard, resource_pack, custom_payload). These parsing errors crash the bot but the packets are not needed for gameplay. This catches and logs them instead of crashing. Also increases checkTimeoutInterval to 60s (from default 30s) to reduce false disconnects on slower servers. These issues affect a large number of users since Paper is the most popular Minecraft server software.
There was a problem hiding this comment.
Pull request overview
This PR addresses connection stability issues when running the Mindcraft bot against Paper/Spigot Minecraft servers by implementing three key changes: packet rate throttling to prevent server kicks, error suppression for non-critical packet parsing failures, and increased keep-alive timeout intervals.
Changes:
- Added 50ms throttle on position/look packets to stay under Paper server packet rate limits
- Suppressed PartialReadError exceptions from unparseable non-critical packets (scoreboard, resource packs, custom payloads)
- Increased keep-alive check interval from 30s to 60s to reduce false disconnects on slower servers
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/utils/mcdata.js
Outdated
| const errStr = String(args[0]); | ||
| if (errStr.includes('PartialReadError')) { | ||
| console.warn('[mcdata] Suppressed PartialReadError:', errStr.substring(0, 100)); | ||
| return true; // Swallow the error |
There was a problem hiding this comment.
The error suppression only checks if the error string includes 'PartialReadError' but doesn't verify that args[0] is actually an Error object. If the error event is emitted with something other than an Error object (null, undefined, or a non-error value), String(args[0]) will convert it, but the check might produce false positives. Add a type check to ensure args[0] exists and is an Error-like object before stringifying it.
| const errStr = String(args[0]); | |
| if (errStr.includes('PartialReadError')) { | |
| console.warn('[mcdata] Suppressed PartialReadError:', errStr.substring(0, 100)); | |
| return true; // Swallow the error | |
| const err = args[0]; | |
| if (err && (err instanceof Error || (typeof err === 'object' && typeof err.message === 'string'))) { | |
| const errStr = String(err); | |
| if (errStr.includes('PartialReadError')) { | |
| console.warn('[mcdata] Suppressed PartialReadError:', errStr.substring(0, 100)); | |
| return true; // Swallow the error | |
| } |
- Queue the last throttled position packet so final position always reaches the server, preventing desync when bot stops moving - Add type guard (instanceof Error) before stringifying error objects - Increase error message truncation to 120 chars for better debugging
Sweaterdog
left a comment
There was a problem hiding this comment.
Interesting! I had been wondering what the PartialReadError was, thanks for the PR!
Sweaterdog
left a comment
There was a problem hiding this comment.
Apologies, I meant to approve, whoops.
|
yes pls i use this on my paper server. |
Summary
Fixes connection stability issues when running Mindcraft against Paper/Spigot servers (the most popular Minecraft server software).
Problem
Paper servers enforce stricter packet rate limits than vanilla Minecraft. This causes two common issues:
node-minecraft-protocolcannot fully parse (scoreboard updates, resource packs, custom payloads). These throwPartialReadErrorwhich crashes the bot.Both issues are widely reported in the community and affect many users since Paper is by far the most popular server software.
Changes
position,position_look, andlookpacketscheckTimeoutInterval: 60000Design Decisions
initBot()inmcdata.jsconsole.warnso they're visible but don't crashRelation to Previous PR
This is a focused subset of the changes from #693, resubmitted as a smaller PR addressing review feedback. The original PR mixed these stability fixes with unrelated feature additions.