docker-compose
docker-compose copied to clipboard
execCompose can throw "RangeError: Invalid string length"
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.
@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?