Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execCompose can throw "RangeError: Invalid string length" #257

Open
laser opened this issue Oct 29, 2023 · 1 comment
Open

execCompose can throw "RangeError: Invalid string length" #257

laser opened this issue Oct 29, 2023 · 1 comment

Comments

@laser
Copy link

laser commented Oct 29, 2023

Context

We have a Docker Compose cluster that we're using to run some tests over night. Our application logs quite a bit to stdout and stderr. After an hour or so, the docker-compose library raises a RangeError: Invalid string length. A quick inspection of the docker-compose library's source code suggests that the problem is the result of buffering Docker Compose output to a string inside of the execCompose function; at some point, we simply exceed the maximum length of a JavaScript string, and crash.

Here's the stack trace that we see:

Users/xxx/yyy/node_modules/docker-compose/dist/v2.js:164
            result.out += chunk.toString();
                                ^
RangeError: Invalid string length
    at Socket.<anonymous> (/Users/xxx/yyy/node_modules/docker-compose/dist/v2.js:164:33)
    at Socket.emit (node:events:526:35)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:343:12)
    at readableAddChunk (node:internal/streams/readable:316:9)
    at Socket.Readable.push (node:internal/streams/readable:253:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Here are the offending subsections of execCompose

    childProc.stdout.on('data', (chunk): void => {
      result.out += chunk.toString()
      options.callback?.(chunk, 'stdout')
    })

    childProc.stderr.on('data', (chunk): void => {
      result.err += chunk.toString()
      options.callback?.(chunk, 'stderr')
    })

Thanks for the great library! We appreciate the work you've all put into it.

@AlexZeitler
Copy link
Contributor

@laser Thanks for reporting and using this library.

Not sure how we could make result.out more other than being a Buffer itself and it would be sort of duplicate of the options.callback.

What would look a reasonable workaround like for you?

Just not throwing and handling the chunks by yourself?

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

No branches or pull requests

2 participants