Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

placeBlock promise chain #2629

Open
1 task done
luizhrios opened this issue May 15, 2022 · 10 comments
Open
1 task done

placeBlock promise chain #2629

luizhrios opened this issue May 15, 2022 · 10 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@luizhrios
Copy link

luizhrios commented May 15, 2022

  • 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

@luizhrios luizhrios added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels May 15, 2022
@luizhrios luizhrios reopened this May 15, 2022
@IceTank
Copy link
Contributor

IceTank commented May 15, 2022

Show the error

@luizhrios
Copy link
Author

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)

@IceTank
Copy link
Contributor

IceTank commented May 15, 2022

Try it with just the try catch block and await

@luizhrios
Copy link
Author

I tried it, same problem. Edited the first comment with the code.

@maximmasiutin
Copy link
Contributor

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)

@IceTank
Copy link
Contributor

IceTank commented Dec 15, 2022

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

@maximmasiutin
Copy link
Contributor

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

@IceTank
Copy link
Contributor

IceTank commented Dec 15, 2022

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.

@SilkePilon
Copy link
Contributor

any updates on this?

@boly38
Copy link
Contributor

boly38 commented Nov 29, 2024

Maybe this one could help (at least to reproduce)
#2757

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

5 participants