Search code examples
javascriptnode.jsruntime-errorminecraftmineflayer

Error: read ECONNRESET at TCP.onStreamRead (node:internal/stream_base_commons:217:20)


I am trying to make a web server for the Mineflayer API for my coding project. It is hosted using the free plan on render.com, and I use a cron job to keep it awake. However, when I send the bot creation request to it, it gives this error, and then continues execution:

Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
{
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}

I tried looking for errors in my code, but I have not found any. The server goes through a switch statement to determine which path to take, and this one is triggered:

case "create":
  let [username, ip, port] = data.split(","); // For now, we only support offline mode.
  let id = crypto.randomBytes(32).toString('hex');
  let bot = mineflayer.createBot({username: username || `Bromine_${id.slice(0, 8)}`, host: ip, port: (port || 25565)});
  bot.messages = [];
  bot.on("message", function(msg, pos) {this.messages.push({jsonMsg: msg, position: pos})});
  bots[id] = {bot: bot};
  var response = {success: true, id: id};
  break;

Edit

The error message is sometimes longer, and may contain more information:

Error: write ECONNRESET
    at afterWriteDispatched (node:internal/stream_base_commons:160:15)
    at writeGeneric (node:internal/stream_base_commons:151:3)
    at Socket._writeGeneric (node:net:962:11)
    at Socket._write (node:net:974:8)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at Framer.ondata (/opt/render/project/src/node_modules/minecraft-protocol/node_modules/readable-stream/lib/internal/streams/readable.js:705:22)
    at Framer.emit (node:events:517:28)
    at addChunk (/opt/render/project/src/node_modules/minecraft-protocol/node_modules/readable-stream/lib/internal/streams/readable.js:321:12)
{
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'write'
}

Solution

  • It seems the error is the equivalent of the connection reset error that can occur when trying to join a Minecraft server. The issue probably came from using an aternos server, since the actual server it is hosted on changes every time.