kriszyp / msgpackr

Ultra-fast MessagePack implementation with extension for record and structural cloning / msgpack.org[JavaScript/NodeJS]
MIT License
473 stars 49 forks source link

Unpack illegal instruction/segfault on Bun #140

Open rgillan opened 1 month ago

rgillan commented 1 month ago

It appears that some of the V8 c++ api's are having issues with some npm modules and we think that unpack may be in the same boat. When we do a simple test on the latest Bun (1.1.20) on both RPi4 and RPi5 it crashes.

var msgpack = require ('msgpack5')();

let sendMsg = {"t":"ce","p":{"cmd":"getdevices","username":"test","domain":"dummy.com","appletId":"dm","filter":"{\"domain\": {\"$in\":[\"au.net\",\"au.ft.net\",\"au.swarm.net\",\"be.dev.net\",\"be.ft.net\",\"be.swarm.net\",\"ci.net\",\"ft.net\",\"qa.net\",\"us.dev.net\",\"us.ft.net\",\"us.swarm.net\"]},\"fields\":[\"_id\",\"dId\",\"domain\",\"status\",\"dto\",\"connection\",\"nwRegion\",\"nwIPAddress\",\"queuedMessages\",\"country\",\"agentRevision\",\"xt\"]}"}};
console.log('send: ' + JSON.stringify(sendMsg));

let packed = pack(sendMsg);
console.log('packed: ' + JSON.stringify(packed));

let rcvMsg = {};
rcvMsg = msgpack.decode(packed);
console.log('works with both: ' + JSON.stringify(rcvMsg));
rcvMsg = unpack(packed);
console.log('works nodejs, fails bun: ' + JSON.stringify(rcvMsg));

We raised this as a Bun issue earlier (and it's being worked on) but they pointed us to: https://github.com/oven-sh/bun/issues/4290

On the RPi4 we get: bun: symbol lookup error: /opt/iotransit/lib/bun/node_modules/msgpackr-extract/build/Release/extract.node: undefined symbol: _ZN2v85Array3NewEPNS_7IsolateEPNS_5LocalINS_5ValueEEEm

On the RPi5 we get:

Linux Kernel v6.8.0 | glibc v2.39
Args: "bun" "run" "testMsgpack.ts"
Features: jsc 
Builtins: "bun:main" "detect-libc" "node:fs" "node:module" "node:os" "node:path" "node:stream" "node:string_decoder" "node:url" "node:util/types" 
Elapsed: 90ms | User: 84ms | Sys: 35ms
RSS: 1.07GB | Peak: 76.04MB | Commit: 1.07GB | Faults: 0

panic(main thread): Segmentation fault at address 0x63696C732E7481

Expect we will need to wait for Bun to address this but thought it worthwhile sharing in case anyone else runs into the same issue. Thanks for all the effort on this module. pack works out of the box and the performance bump is great.

rgillan commented 1 month ago

updating from Bun for reference: Sorry, I'd mistyped your reproduction. I can reproduce a segfault which occurs if libnode109 is installed, because msgpackr-extract picks up the definition of v8::Array::New and calls it with JSC values while that expects V8 values. Weirdly, I don't get the missing symbol error if libnode109 is not installed, instead it runs properly.