sockjs / sockjs-node

WebSocket emulation - Node.js server
http://sockjs.org
MIT License
2.1k stars 309 forks source link

Heap OOM in utils.quote regex test #237

Open priyadarshy opened 6 years ago

priyadarshy commented 6 years ago

I have a meteor web app that uses sockjs under the hood. Occasionally, I see this OOM issue, and it always points to the same line of code.

Is there something I can do to workaround this.

<--- Last few GCs --->

[198:0x27e6e00]   786430 ms: Mark-sweep 1207.1 (1399.4) -> 1207.0 (1402.9) MB, 1438.7 / 0.0 ms  allocation failure GC in old space requested
[198:0x27e6e00]   787804 ms: Mark-sweep 1207.0 (1402.9) -> 1206.9 (1347.9) MB, 1374.4 / 0.0 ms  last resort GC in old space requested
[198:0x27e6e00]   789262 ms: Mark-sweep 1206.9 (1347.9) -> 1206.9 (1324.4) MB, 1457.5 / 0.0 ms  last resort GC in old space requested

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x2576aed25ee1 <JSObject>
    1: test(this=0x16002e479b91 <JSRegExp <String[76]: [\x00-\x1f\ud800-\udfff\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufff0-\uffff]>>,0x181100c0a539 <Very long string[198024197]>)
    3: quote [/opt/app/programs/server/npm/node_modules/meteor/ddp-server/node_modules/sockjs/lib/utils.js:124] [bytecode=0x14f91990c5d1 offset=38](this=0x2d252d7d299 <Object map = 0x39f53b37fb39>,string=0x34b16cc30311...

 1: node::Abort() [node]
 2: 0x121a7ac [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [node]
 7: v8::internal::RegExpImpl::IrregexpExec(v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>, int, v8::internal::Handle<v8::internal::RegExpMatchInfo>) [node]
 8: v8::internal::RegExpImpl::Exec(v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>, int, v8::internal::Handle<v8::internal::RegExpMatchInfo>) [node]
 9: v8::internal::Runtime_RegExpExec(int, v8::internal::Object**, v8::internal::Isolate*) [node]
10: 0x356b0570463d
brycekahle commented 6 years ago

Are you sending large payloads? I don't see any other reason why that method would requite a lot of memory.