Skip to content

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

Open
@laser

Description

@laser

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions