PrismarineJS / mineflayer-collectblock

A simple utility plugin for Mineflayer that add a higher level API for collecting blocks.
MIT License
38 stars 23 forks source link

JS heap out of memory for the example task #133

Open milesway opened 4 months ago

milesway commented 4 months ago

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 commented 4 months ago

You are not waiting for promises correctly.

milesway commented 4 months ago

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.