Skip to content

fix: improve connection stability for Paper/Spigot servers#704

Open
atiweb wants to merge 2 commits intomindcraft-bots:developfrom
atiweb:feat/paper-server-stability
Open

fix: improve connection stability for Paper/Spigot servers#704
atiweb wants to merge 2 commits intomindcraft-bots:developfrom
atiweb:feat/paper-server-stability

Conversation

@atiweb
Copy link

@atiweb atiweb commented Feb 6, 2026

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:

  1. ECONNRESET kicks — Mineflayer sends position/look packets very rapidly. Paper enforces a packet-per-tick limit and disconnects clients that exceed it.
  2. PartialReadError crashes — Paper sends some packets that node-minecraft-protocol cannot fully parse (scoreboard updates, resource packs, custom payloads). These throw PartialReadError which 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

Change What Why
Position packet throttling Minimum 50ms between position, position_look, and look packets Stays under Paper's packet rate limit
PartialReadError suppression Catch and log parsing errors for non-critical packets Prevents crashes on packets we don't need
checkTimeoutInterval: 60000 Increase keep-alive check from 30s to 60s Reduces false disconnects on slower servers

Design Decisions

  • Minimal and focused — only modifies initBot() in mcdata.js
  • No new dependencies
  • Transparent — suppressed errors are logged with console.warn so they're visible but don't crash
  • Conservative throttle — 50ms is well under Paper's limit while still allowing smooth movement
  • Vanilla-compatible — these changes don't affect vanilla server behavior since vanilla doesn't enforce these limits

Relation 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.

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.
Copilot AI review requested due to automatic review settings February 6, 2026 02:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +94 to +97
const errStr = String(args[0]);
if (errStr.includes('PartialReadError')) {
console.warn('[mcdata] Suppressed PartialReadError:', errStr.substring(0, 100));
return true; // Swallow the error
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
- 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
Copy link
Contributor

@Sweaterdog Sweaterdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! I had been wondering what the PartialReadError was, thanks for the PR!

Copy link
Contributor

@Sweaterdog Sweaterdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I meant to approve, whoops.

@bobo384win
Copy link

yes pls i use this on my paper server.

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.

4 participants