While using an Node.js MQTT broker https://github.com/mcollina/mosca I and others have been running into an issue with amqp throwing a Maximum call stack size exceeded error originating in amqp parser.
Error usually looks like:
Server: RangeError: Maximum call stack size exceeded
at min (native)
at Buffer.subarray (native)
at Buffer.slice (buffer.js:617:23)
at allocate (buffer.js:88:23)
at new Buffer (buffer.js:53:12)
at parseFields (/root/mqtt-load-test/basic-broker/node_modules/amqp/lib/parser.js:315:17)
at AMQPParser._parseMethodFrame (/root/mqtt-load-test/basic-broker/node_modules/amqp/lib/parser.js:359:14)
at frameEnd (/root/mqtt-load-test/basic-broker/node_moduleas/amqp/lib/parser.js:93:16)
at frame (/root/mqtt-load-test/basic-broker/node_modules/amqp/lib/parser.js:78:14)
at header (/root/mqtt-load-test/basic-broker/node_modules/amqp/lib/parser.js:64:14)
Because lib/parser parses the incoming buffer recursively if you supply too large of a buffer that contains many amqp packets it eventually will reach the maximum stack size while parsing. In production we're seeing a large buffer with the size of 65536 get emitted from https://github.com/postwait/node-amqp/blob/master/lib/connection.js#L171 which then throws the error when execute() is called.
Not sure the best approach to solve the issue as amqp handles both parsing of the data and the underlying network connection. In a quick fix i modified the data event in lib/connection to spoon feed the incoming data in chunks no larger than 10000 bytes. Seems to fix our specific use case.
I'm running node version v4.2.1 and amqp version 0.2.4
While using an Node.js MQTT broker https://github.com/mcollina/mosca I and others have been running into an issue with amqp throwing a
Maximum call stack size exceeded
error originating inamqp
parser.Error usually looks like:
Because
lib/parser
parses the incoming buffer recursively if you supply too large of a buffer that contains many amqp packets it eventually will reach the maximum stack size while parsing. In production we're seeing a large buffer with the size of 65536 get emitted from https://github.com/postwait/node-amqp/blob/master/lib/connection.js#L171 which then throws the error whenexecute()
is called.Not sure the best approach to solve the issue as amqp handles both parsing of the data and the underlying network connection. In a quick fix i modified the
data
event inlib/connection
to spoon feed the incoming data in chunks no larger than 10000 bytes. Seems to fix our specific use case.I'm running node version
v4.2.1
and amqp version0.2.4
Patch looks like: Using the spoon feed method
Here is a test file that replicates what's happening in production: