mineflayer
mineflayer copied to clipboard
placeBlock promise chain
- [x] The FAQ doesn't contain a resolution to my issue
Versions
- mineflayer: 4.3.0
- server: Idk
- node: v17.7.2
Detailed description of a problem
placeBlock sometimes break out of the promise chain and because of that, no catches and crashes when errors happens.
Seens to be related to when the block the bot is trying to place is out of reach, and times out after the attempt.
EDIT
(node:36276) UnhandledPromiseRejectionWarning: Error: Event blockUpdate:(703010, -1, 190296) did not fire within timeout of 5000ms
at onceWithCleanup (\node_modules\mineflayer\lib\promise_utils.js:62:26)
at placeBlockWithOptions (\node_modules\mineflayer\lib\plugins\place_block.js:13:36)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async EventEmitter.placeBlock (\node_modules\mineflayer\lib\plugins\place_block.js:24:5)
at async Timeout._onTimeout (\main.js:243:7)
What did you try yet?
Using .then(onfulfilled, onrejected) Using .then().catch() Using try catch with async
Ended up settings unhandled exceptions to warn.
Your current code
let farmlands = bot.findBlocks({
matching: [mcData.blocksByName["farmland"].id],
maxDistance: 6,
count: Infinity
});
let emptyFarmlands = farmlands.filter(coords => bot.blockAt(coords.offset(0, 1, 0)).name === "air");
let coords = emptyFarmlands[0];
try {
await bot.placeBlock(bot.blockAt(coords), new Vec3(0, 1, 0)).then(() => {}, reason => {
console.log("Error then onrejected", coords, reason)
}).catch(reason => {
console.log("Error promise catch", coords, reason)
});
} catch (error) {
console.log("Error", coords, error)
}
let farmlands = bot.findBlocks({
matching: [mcData.blocksByName["farmland"].id],
maxDistance: 6,
count: Infinity
});
let emptyFarmlands = farmlands.filter(coords => bot.blockAt(coords.offset(0, 1, 0)).name === "air");
let coords = emptyFarmlands[0];
try {
await bot.placeBlock(bot.blockAt(coords), new Vec3(0, 1, 0));
} catch (error) {
console.log("Error", coords, error)
}
Expected behavior
Catch errors when place block fails somehow
Show the error
Sorry, forgot.
(node:36276) UnhandledPromiseRejectionWarning: Error: Event blockUpdate:(703010, -1, 190296) did not fire within timeout of 5000ms
at onceWithCleanup (\node_modules\mineflayer\lib\promise_utils.js:62:26)
at placeBlockWithOptions (\node_modules\mineflayer\lib\plugins\place_block.js:13:36)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async EventEmitter.placeBlock (\node_modules\mineflayer\lib\plugins\place_block.js:24:5)
at async Timeout._onTimeout (\main.js:243:7)
Try it with just the try catch block and await
I tried it, same problem. Edited the first comment with the code.
I have the same error still with Mineflayer 4.5.1 :(
Error: Event blockUpdate:(421, 71, -263) did not fire within timeout of 5000ms
at onceWithCleanup (.\mineflayer\node_modules\mineflayer\lib\promise_utils.js:62:26)
at placeBlockWithOptions (.\mineflayer\node_modules\mineflayer\lib\plugins\place_block.js:13:36)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async EventEmitter.placeBlock (.\mineflayer\node_modules\mineflayer\lib\plugins\place_block.js:24:5)
This should be fixed with this merge request https://github.com/PrismarineJS/mineflayer/pull/2833/files The issue is that there is a unhandled promise rejection in the onceWithCleanup function that is used by placeBlock
@IceTank - thank you for letting us know. I also run a program with set DEBUG=minecraft-protocol and figured out that when there are many entities around a player (e.g. a five hundred sheep, cows and cattle), lots of packets are coming to denote the move for each of the entities, and the error "Event blockUpdate....did not fire within timeout of 5000ms" soon arrives, after about 2-3 placeBlock's. However, if I remove all these entities, hundreds of placeBlock's succeed until eventually giving the same error. The network connection is very good and the native game client works without lags.
This sounds like the node process is not keeping up with event handling. No one really tests mineflayer's performance when you have lots off entities or block updates. You can try debugging the issue with https://nodejs.org/en/docs/guides/debugging-getting-started/#inspector-clients . Chromium based browsers can also record a process to list off functions that take up a lot off processing time. If you find a function that takes up to much time you can make an issue or a pull reuqest to fix it in mineflayer. There are definitely ways to improves mineflayers performance.
any updates on this?