abalabahaha / opusscript

JS bindings for libopus 1.4, ported with Emscripten
MIT License
62 stars 18 forks source link

When connecting to a large number of servers, Emscripten doesn't like the memory usage #1

Closed bitnimble closed 7 years ago

bitnimble commented 7 years ago

When connecting to a large number of servers on a VoiceConnection in Eris, each VC spins up an OpusScript instance. In the constructor for OpusScript, some memory is malloc'd for the native wrapper - with so many servers, it pushes it over the 16MB limit that Emscripten has. The solution is to apparently just recompile the native library with -s ALLOW_MEMORY_GROWTH=1. We got this error with around ~80 servers, ymmv.

Call stack:

Error: Uncaught, unspecified "error" event. (abort("Cannot enlarge memory arrays. Either (1) compile with  -s TOTAL_MEMORY=X  with X higher than the current value 16777216, (2) compile with  -s ALLOW_MEMORY_GROWTH=1  which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with  -s ABORTING_MALLOC=0 ") at Error
    at jsStackTrace (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:1:15924)
    at stackTrace (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:1:16107)
    at abort (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:16:4919)
    at abortOnCannotGrowMemory (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:1:16868)
    at enlargeMemory (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:1:17313)
    at Function.dynamicAlloc [as alloc] (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:1:7041)
    at _sbrk (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:1:166858)
    at Object.He [as _malloc] (/home/kanadeko/radiobot/node_modules/opusscript/build/opusscript_native.js:8:74554)
    at new OpusScript (/home/kanadeko/radiobot/node_modules/opusscript/index.js:47:44)
    at new VoiceConnection (/home/kanadeko/radiobot/node_modules/eris/lib/voice/VoiceConnection.js:62:25)```