PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.93k stars 905 forks source link

Keepalive timeout #2076

Open JIBSIL opened 3 years ago

JIBSIL commented 3 years ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. What are you building? What problem are you trying to solve?

I am building a pathfinding bot with Mineflayer viewer.

What did you try yet?

I am not sure what to try because I don't know what the problem is (vague error) Did you try any method from the API? n/a Did you try any example? Any error from those? n/a, unique issue

Your current code

const mineflayer = require('mineflayer')
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
const { pathfinder, Movements, goals: { GoalNearXZ } } = require('mineflayer-pathfinder')

const bot = mineflayer.createBot({
    host: '192.168.1.87',
    port: '25571',
    username: 'firefox',
})

bot.loadPlugin(pathfinder)

bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3007, firstPerson: false })
  const mcData = require('minecraft-data')(bot.version)
  const defaultMove = new Movements(bot, mcData)
  bot.pathfinder.setMovements(defaultMove)
  function getRandomInt(max) {
    return Math.floor(Math.random() * max);
  }
  var random = [getRandomInt(6553), getRandomInt(6553)]
  console.log(`Moving to X ${random[0]}, Z ${random[1]}`)
  bot.pathfinder.setGoal(new GoalNearXZ(random[0], random[1], 1))
})

bot.on('kicked', console.log)
bot.on('error', console.log)
bot.on('end', console.log)

Expected behavior

The bot is able to stay as long as it likes

Observed behaviour

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:769:11) at Socket._write (node:net:781:8) at writeOrBuffer (node:internal/streams/writable:389:12) at _write (node:internal/streams/writable:330:10) at Socket.Writable.write (node:internal/streams/writable:334:10) at Framer.ondata (C:\Users\TheEb\Desktop\Code\McSPAM\node_modules\readable-stream\lib_stream_readable.js:681:20) at Framer.emit (node:events:394:28) at addChunk (C:\Users\TheEb\Desktop\Code\McSPAM\node_modules\readable-stream\lib_stream_readable.js:298:12) { errno: -4077, code: 'ECONNRESET', syscall: 'write' }

[14:49:39 WARN]: firefox was kicked due to keepalive timeout! on server side

Additional context

Add any other context about the problem here.

kashalls commented 3 years ago

I am unable to reproduce this.

My Code:

const mineflayer = require('mineflayer')
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
const { pathfinder, Movements, goals: { GoalNearXZ } } = require('mineflayer-pathfinder')

const bot = mineflayer.createBot({
    host: '127.0.0.1',
    port: '25565',
    username: 'emailRedacted',
    auth: 'microsoft',
    version: '1.16.5'
})

bot.loadPlugin(pathfinder)

bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3007, firstPerson: false })
  const mcData = require('minecraft-data')(bot.version)
  const defaultMove = new Movements(bot, mcData)
  bot.pathfinder.setMovements(defaultMove)
  function getRandomInt(max) {
    return Math.floor(Math.random() * max);
  }
  var random = [getRandomInt(6553), getRandomInt(6553)]
  console.log(`Moving to X ${random[0]}, Z ${random[1]}`)
  bot.pathfinder.setGoal(new GoalNearXZ(random[0], random[1], 1))
})

bot.on('kicked', console.log)
bot.on('error', console.log)
bot.on('end', console.log)

Yatopia Server: #122 https://ci.codemc.io/job/YatopiaMC/job/Yatopia/job/ver%252F1.16.5/lastSuccessfulBuild/

My best guess is you are on WiFi had some stability issues as you are (possibly) using another computer on the same lan.

JIBSIL commented 3 years ago

I am unable to reproduce this.

My Code:

const mineflayer = require('mineflayer')
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
const { pathfinder, Movements, goals: { GoalNearXZ } } = require('mineflayer-pathfinder')

const bot = mineflayer.createBot({
    host: '127.0.0.1',
    port: '25565',
    username: 'emailRedacted',
    auth: 'microsoft',
    version: '1.16.5'
})

bot.loadPlugin(pathfinder)

bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3007, firstPerson: false })
  const mcData = require('minecraft-data')(bot.version)
  const defaultMove = new Movements(bot, mcData)
  bot.pathfinder.setMovements(defaultMove)
  function getRandomInt(max) {
    return Math.floor(Math.random() * max);
  }
  var random = [getRandomInt(6553), getRandomInt(6553)]
  console.log(`Moving to X ${random[0]}, Z ${random[1]}`)
  bot.pathfinder.setGoal(new GoalNearXZ(random[0], random[1], 1))
})

bot.on('kicked', console.log)
bot.on('error', console.log)
bot.on('end', console.log)

Yatopia Server: #122 https://ci.codemc.io/job/YatopiaMC/job/Yatopia/job/ver%252F1.16.5/lastSuccessfulBuild/

My best guess is you are on WiFi had some stability issues as you are (possibly) using another computer on the same lan.

Is there a way to catch this error before it makes the bot leave the server?

JIBSIL commented 3 years ago

Also getting this: Is this because of lag? Error: Event blockUpdate:(124, 72, 302) did not fire within timeout of 5000ms

kashalls commented 3 years ago

I am unable to reproduce this.

My Code:

const mineflayer = require('mineflayer')
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
const { pathfinder, Movements, goals: { GoalNearXZ } } = require('mineflayer-pathfinder')

const bot = mineflayer.createBot({
    host: '127.0.0.1',
    port: '25565',
    username: 'emailRedacted',
    auth: 'microsoft',
    version: '1.16.5'
})

bot.loadPlugin(pathfinder)

bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3007, firstPerson: false })
  const mcData = require('minecraft-data')(bot.version)
  const defaultMove = new Movements(bot, mcData)
  bot.pathfinder.setMovements(defaultMove)
  function getRandomInt(max) {
    return Math.floor(Math.random() * max);
  }
  var random = [getRandomInt(6553), getRandomInt(6553)]
  console.log(`Moving to X ${random[0]}, Z ${random[1]}`)
  bot.pathfinder.setGoal(new GoalNearXZ(random[0], random[1], 1))
})

bot.on('kicked', console.log)
bot.on('error', console.log)
bot.on('end', console.log)

Yatopia Server: #122 https://ci.codemc.io/job/YatopiaMC/job/Yatopia/job/ver%252F1.16.5/lastSuccessfulBuild/

My best guess is you are on WiFi had some stability issues as you are (possibly) using another computer on the same lan.

Is there a way to catch this error before it makes the bot leave the server?

You can't catch this error. It is considered a "fatal error" as the communication between you and the remote server have been disconnected.

JIBSIL commented 3 years ago

I am unable to reproduce this. My Code:

const mineflayer = require('mineflayer')
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
const { pathfinder, Movements, goals: { GoalNearXZ } } = require('mineflayer-pathfinder')

const bot = mineflayer.createBot({
    host: '127.0.0.1',
    port: '25565',
    username: 'emailRedacted',
    auth: 'microsoft',
    version: '1.16.5'
})

bot.loadPlugin(pathfinder)

bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3007, firstPerson: false })
  const mcData = require('minecraft-data')(bot.version)
  const defaultMove = new Movements(bot, mcData)
  bot.pathfinder.setMovements(defaultMove)
  function getRandomInt(max) {
    return Math.floor(Math.random() * max);
  }
  var random = [getRandomInt(6553), getRandomInt(6553)]
  console.log(`Moving to X ${random[0]}, Z ${random[1]}`)
  bot.pathfinder.setGoal(new GoalNearXZ(random[0], random[1], 1))
})

bot.on('kicked', console.log)
bot.on('error', console.log)
bot.on('end', console.log)

Yatopia Server: #122 https://ci.codemc.io/job/YatopiaMC/job/Yatopia/job/ver%252F1.16.5/lastSuccessfulBuild/ My best guess is you are on WiFi had some stability issues as you are (possibly) using another computer on the same lan.

Is there a way to catch this error before it makes the bot leave the server?

You can't catch this error. It is considered a "fatal error" as the communication between you and the remote server have been disconnected.

But I could always wrap it in a trycatch and use this?

function makeBot() {
// the code
}
try {
makeBot()
}
catch(e) {
console.log('disconnected, reconnecting')
makeBot()
}
kashalls commented 3 years ago

It would be easier to use a process manager such as pm2 to restart the script when it exits. This would just make it start again after it errors out and then it would just crash after the second.

You might want to find out first why you're having network issues in the first place.

JIBSIL commented 3 years ago

Thanks for the advice. My network is fine, I can watch netflix on mutliple screens, I run my own minecraft server.. it must be something with my computer or mineflayer

u9g commented 3 years ago

Try restarting your pc

rom1504 commented 3 years ago

try checkTimeoutInterval:60*1000 (but default is 30s so if you're lagging that hard nothing will work anyway)

what is your ping with that server ? (do ping <server ip> in the term)