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

JS heap out of memory for the example task #133

Open
milesway opened this issue Apr 26, 2024 · 3 comments
Open

JS heap out of memory for the example task #133

milesway opened this issue Apr 26, 2024 · 3 comments

Comments

@milesway
Copy link

milesway commented Apr 26, 2024

Program exit with
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
when executing the sample task:

const mineflayer = require('mineflayer')

const bot = mineflayer.createBot({
  host: 'localhost', 
  username: 'bot1', 
  auth: 'offline',
  port: 2037,  
})

// Load collect block
bot.loadPlugin(require('mineflayer-collectblock').plugin)

async function collectStone() {
  // Find a nearby stone block
  const stone = bot.findBlock({
    matching: mcData.blocksByName.stone.id,
    maxDistance: 64
  })

  if (stone) {
    // If we found one, collect it.
    try {
      await bot.collectBlock.collect(stone)
      collectStone() // Collect another stone block
    } catch (err) {
      console.log(err) // Handle errors, if any
    }
  }
}
// On spawn, start collecting all nearby stone
bot.once('spawn', () => {
  mcData = require('minecraft-data')(bot.version)
  collectStone()
})

The console log:

<--- Last few GCs --->

[68251:0x150008000]    39126 ms: Scavenge 3922.6 (4120.0) -> 3913.3 (4120.0) MB, 11.21 / 0.00 ms  (average mu = 0.120, current mu = 0.005) allocation failure; 
[68251:0x150008000]    39190 ms: Scavenge 3924.5 (4120.2) -> 3918.3 (4124.0) MB, 54.75 / 0.00 ms  (average mu = 0.120, current mu = 0.005) allocation failure; 
[68251:0x150008000]    39228 ms: Scavenge 3932.8 (4126.2) -> 3925.3 (4130.2) MB, 18.88 / 0.00 ms  (average mu = 0.120, current mu = 0.005) allocation failure; 


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0x1047a153c node::Abort() [/usr/local/bin/node]
 2: 0x1047a173c node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/usr/local/bin/node]
 3: 0x1049266c4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/usr/local/bin/node]
 4: 0x104afadb8 v8::internal::Heap::GarbageCollectionReasonToString(v8::internal::GarbageCollectionReason) [/usr/local/bin/node]
 5: 0x104afec6c v8::internal::Heap::CollectGarbageShared(v8::internal::LocalHeap*, v8::internal::GarbageCollectionReason) [/usr/local/bin/node]
 6: 0x104afb6d0 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [/usr/local/bin/node]
 7: 0x104af9458 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x104af00ac v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 9: 0x104af090c v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x104ad5568 v8::internal::Factory::AllocateRawWithAllocationSite(v8::internal::Handle<v8::internal::Map>, v8::internal::AllocationType, v8::internal::Handle<v8::internal::AllocationSite>) [/usr/local/bin/node]
11: 0x104ae2710 v8::internal::Factory::NewJSGeneratorObject(v8::internal::Handle<v8::internal::JSFunction>) [/usr/local/bin/node]
12: 0x104ebb808 v8::internal::Runtime_CreateJSGeneratorObject(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0x10521cc44 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
14: 0x1051cd060 Builtins_CreateGeneratorObject [/usr/local/bin/node]
15: 0x10a86bf4c 
16: 0x10a86ab60 
17: 0x1051cd4c4 Builtins_GeneratorPrototypeNext [/usr/local/bin/node]
18: 0x10a865918 
19: 0x105278fb8 Builtins_PromiseFulfillReactionJob [/usr/local/bin/node]
20: 0x1051bab94 Builtins_RunMicrotasks [/usr/local/bin/node]
21: 0x1051923f4 Builtins_JSRunMicrotasksEntry [/usr/local/bin/node]
22: 0x104a68238 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
23: 0x104a68724 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
24: 0x104a68900 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [/usr/local/bin/node]
25: 0x104a8facc v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/usr/local/bin/node]
26: 0x104a90268 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/usr/local/bin/node]
27: 0x1046d0c64 node::InternalCallbackScope::Close() [/usr/local/bin/node]
28: 0x1046d07c4 node::InternalCallbackScope::~InternalCallbackScope() [/usr/local/bin/node]
29: 0x104747930 node::Environment::RunTimers(uv_timer_s*) [/usr/local/bin/node]
30: 0x10516ec44 uv__run_timers [/usr/local/bin/node]
31: 0x1051724a4 uv_run [/usr/local/bin/node]
32: 0x1046d1754 node::SpinEventLoopInternal(node::Environment*) [/usr/local/bin/node]
33: 0x1047e1b8c node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/usr/local/bin/node]
34: 0x1047e1928 node::NodeMainInstance::Run() [/usr/local/bin/node]
35: 0x10476b6b8 node::Start(int, char**) [/usr/local/bin/node]
36: 0x19346a0e0 start [/usr/lib/dyld]

Process finished with exit code 134 (interrupted by signal 6:SIGABRT)

The stone is right next to the agent, and agent is not mining.

@extremeheat
Copy link
Member

You are not waiting for promises correctly.

@milesway
Copy link
Author

milesway commented Apr 26, 2024

You are not waiting for promises correctly.

@extremeheat Could you elaborate more about how to do it? As it is the example code on README I am using.

@reecelikesramen
Copy link

@extremeheat I've got a similar issue and I think I properly awaited it. After about 30 seconds node crashes. During this time its also entirely blocking and other events aren't firing. Here's a minimal example reproducing it:

import mineflayer from "mineflayer"
import collectblock from "mineflayer-collectblock"

const bot = mineflayer.createBot({
  host: "localhost",
  port: 51870,
  username: "test",
})

bot.once("spawn", () => {
  bot.loadPlugin(collectblock.plugin)

  setTimeout(async () => {
    bot.chat("Doing some stuff now!")

    const blocks = bot.findBlocks({
      matching: 1, // stone
      maxDistance: 32,
      count: 2,
    })

    const targets = blocks.map((block) => bot.blockAt(block))
    await bot.collectBlock.collect(targets, { ignoreNoPath: true })
    bot.chat("done")
  }, 1000)
})

bot.on("chat", (username, message) => {
  console.log(`Chat> ${username}: ${message}`)
})

Some observations:

  • The bot never chats "done"
  • It will correct path-find to the block
  • During the collectBlock, chats do not get logged to console
  • The mineflayer bot stops sending packets to the server, i.e. after "Doing some stuff now!", teleport it in the air and it will not fall.

There is inconsistent behavior if the bot's inventory is empty vs. if it has a tool to mine the stone. Also, if you adjust the findBlocks count sufficiently high, sometimes it will mine a block or two, but not all of them.

After about 30 seconds it crashes with a similar error:

% node index.js
Chat> test: Doing some stuff now!

<--- Last few GCs --->

[75204:0x130008000]    33732 ms: Scavenge 1972.1 (2076.4) -> 1964.9 (2080.9) MB, 17.42 / 0.00 ms  (average mu = 0.366, current mu = 0.355) allocation failure; 
[75204:0x130008000]    38928 ms: Mark-Compact 1978.5 (2082.9) -> 1951.4 (2086.6) MB, 5179.21 / 0.00 ms  (average mu = 0.212, current mu = 0.098) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0x102643eb8 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 2: 0x1027d262c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 3: 0x1029a6d00 v8::internal::Heap::GarbageCollectionReasonToString(v8::internal::GarbageCollectionReason) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 4: 0x1029aabb4 v8::internal::Heap::CollectGarbageShared(v8::internal::LocalHeap*, v8::internal::GarbageCollectionReason) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 5: 0x1029a7618 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 6: 0x1029a53a0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 7: 0x10299bff4 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 8: 0x10299c854 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
 9: 0x1029818c4 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
10: 0x102d695d4 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
11: 0x1030c8c44 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
12: 0x10850a44c 
13: 0x1030794c4 Builtins_GeneratorPrototypeNext [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
14: 0x108508748 
15: 0x1030794c4 Builtins_GeneratorPrototypeNext [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
16: 0x1086285d8 
17: 0x103124fb8 Builtins_PromiseFulfillReactionJob [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
18: 0x103066b94 Builtins_RunMicrotasks [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
19: 0x10303e3f4 Builtins_JSRunMicrotasksEntry [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
20: 0x102914180 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
21: 0x10291466c v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
22: 0x102914848 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
23: 0x10293ba14 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
24: 0x10293c1b0 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
25: 0x10256cc4c node::InternalCallbackScope::Close() [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
26: 0x10256c7bc node::InternalCallbackScope::~InternalCallbackScope() [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
27: 0x1025e5514 node::Environment::RunTimers(uv_timer_s*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
28: 0x10301ac14 uv__run_timers [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
29: 0x10301e474 uv_run [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
30: 0x10256d6f0 node::SpinEventLoopInternal(node::Environment*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
31: 0x102683b64 node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
32: 0x102683878 node::NodeMainInstance::Run() [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
33: 0x10260b654 node::Start(int, char**) [/Users/rholmdahl/.nvm/versions/node/v20.18.0/bin/node]
34: 0x18e2c0274 start [/usr/lib/dyld]
zsh: abort      node index.js

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

No branches or pull requests

3 participants