Skip to content

Fix files left only as .backup when a run stops #813

Closed

Description

@mathiasrw

Today

When one file fails in the middle of a run, the CLI ends the process while other files are halfway through being written. A file is written by renaming it to a .backup, writing the new content, and then removing the backup. A file that is cut off between the first two steps is left only as .backup, and the original is gone.

for i in $(seq -w 0 199); do printf foo > b$i.txt; done
rexreplace foo "if (filename === 'b050.txt') throw new Error('boom'); 'bar'" "b*.txt" --js
ls b*.txt | grep -vc backup    # less than 200
Version Originals missing, out of 200
7.1.14 about 50
main 1 to 3
with #811 and a write error with --halt 15

It happens with and without --halt, for a panic and for a write error.

The cause: the workers run with Promise.all, which rejects at the first error while the other workers are still in the middle of a file, and then the CLI calls process.exit(3).

Change

Let the engine wait for all workers with Promise.allSettled, and then throw the first error. Then the CLI only ends the process when every file in work is done. With --halt no new file is started (#789), but a file in work is always finished.

Tests

A test that checks the files themselves after the run: no file is missing, and there is no .backup.

Good to know

#809 and #811 say this is handled, but their tests only check the exit code. Found in the review of 23 October.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions