Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Uncaught Exception: RangeError: Invalid string length #80

Closed
SimonSimCity opened this issue Sep 29, 2019 · 4 comments
Closed

Uncaught Exception: RangeError: Invalid string length #80

SimonSimCity opened this issue Sep 29, 2019 · 4 comments

Comments

@SimonSimCity
Copy link

SimonSimCity commented Sep 29, 2019

After posting tons of very big span or transaction object, my process crashed by this exception:

Uncaught Exception: RangeError: Invalid string length
    at objs.reduce (./my-project/node_modules/elastic-apm-http-client/index.js:272:19)
    at Array.reduce (<anonymous>)
    at Client._writevCleaned (./my-project/node_modules/elastic-apm-http-client/index.js:271:22)
    at processBatch (./my-project/node_modules/elastic-apm-http-client/index.js:249:12)
    at Client._writev (./my-project/node_modules/elastic-apm-http-client/index.js:267:3)
    at doWrite (./my-project/node_modules/readable-stream/lib/_stream_writable.js:405:97)
    at clearBuffer (./my-project/node_modules/readable-stream/lib/_stream_writable.js:501:5)
    at onwrite (./my-project/node_modules/readable-stream/lib/_stream_writable.js:451:7)
    at WritableState.onwrite (./my-project/node_modules/readable-stream/lib/_stream_writable.js:158:5)
    at afterWrite (./my-project/node_modules/readable-stream/lib/_stream_writable.js:465:3)
    at onwrite (./my-project/node_modules/readable-stream/lib/_stream_writable.js:457:7)
    at WritableState.onwrite (./my-project/node_modules/readable-stream/lib/_stream_writable.js:158:5)
    at StreamChopper.ondrain [as _ondrain] (./my-project/node_modules/stream-chopper/index.js:59:5)
    at StreamChopper._removeStream (./my-project/node_modules/stream-chopper/index.js:182:45)
    at StreamChopper._endStream (./my-project/node_modules/stream-chopper/index.js:165:8)
    at StreamChopper._maybeEndTransformSteam (./my-project/node_modules/stream-chopper/index.js:137:27)
    at Gzip._stream.on.chunk (./my-project/node_modules/stream-chopper/index.js:94:14)
    at emitOne (events.js:121:20)
    at Gzip.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Gzip.Readable.push (_stream_readable.js:208:10)
    at Gzip.Transform.push (_stream_transform.js:147:32)
    at Zlib.callback (zlib.js:474:14)
@Qard
Copy link
Contributor

Qard commented Sep 30, 2019

What are you sending that's that big? That's an out-of-memory error. 🤔

Can you share more details about what the individual span/transaction object looks like and why it's so big?

@SimonSimCity
Copy link
Author

Well, it's related to the issue I referred to (https://github.com/kschingiz/meteor-elastic-apm/pull/34) - which is kind of a longer story.

We're monitoring a framework called Meteor, which provides the option to send "commands" (they refer to it as calling a method) over the wire. All of those are logged including their data. Imagine calling a save method giving it some parameters - the name of the method and the parameters are sent to the server via a socket connection.

Now - one of the packages uses this technology to upload files. It splits the file up into chunks on the server side and then sends partial-upload-calls to the server containing the files content as argument; and this method (and thereby also it's logging including the full parameters) is called very often within a second. This brings this library to crash.

It's one side of a coin that this clearly is not as this library was intended to be used, but it also surprises me that this library doesn't have a security layer in place here to prevent the system from crashing.

@SimonSimCity
Copy link
Author

SimonSimCity commented Oct 9, 2019

I found some resources saying a string in nodejs has a maximum length (nodejs/help#712). It could well be that this already will postpone the problem by such a margin that it doesn't affect us anymore, but I guess it'll come back one day 😄

@Qard
Copy link
Contributor

Qard commented Oct 16, 2019

Yes, there is a max string size in JavaScript itself, and there's nothing we can do about that. We do have a bunch of protections in place to avoid crashing the process, but there's not a whole lot that can be done when the process runs out of memory. 🤷‍♂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants