zx icon indicating copy to clipboard operation
zx copied to clipboard

Long-running processes crash with "Invalid string length"

Open matthewvalentine opened this issue 2 years ago • 2 comments

Expected Behavior

I should be able to run a process that logs large amounts to stderr, as long as I don't need the full output as a single string at the end (for example, because it is already being piped or logged). To allow that, it's fine if it requires calling some extra method on $., it just should be possible.

Actual Behavior

Eventually, if the command outputs enough to stderr, the program crashes with

zx/build/core.js:172
            combined += data;
                        ^
RangeError: Invalid string length

The same can happen with stdout if the command is not piped, but stderr is unconditional, and there's nothing you can do to prevent it.

This happens because ZX is recording the entire stderr history (and stdout, if not piped) regardless of whether the caller will ever read that full output as a single unit. This eventually reaches the JS max string length and ZX will crash.

Steps to Reproduce the Problem

  1. Make a script that continuously logs to stderr
  2. Try to run that script via ZX
  3. No configuration of pipe / quiet / whatever will prevent ZX hitting the max string length

Specifications

  • Version: 7.2.1
  • Platform: Mac OS 13.4.1

matthewvalentine avatar Jul 19 '23 19:07 matthewvalentine

True. Will work on some api to simplify this process.

antonmedv avatar Jul 20 '23 08:07 antonmedv

Are there any workarounds for this? I have seen this issue a number of times now.

schlenks avatar Sep 08 '23 18:09 schlenks