Skip to content

Assets missing + nondeterministic build (probable regression?) #2018

@SmallhillCZ

Description

@SmallhillCZ

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

This is a probable regression from already closed issues (see below). When machine is slow or slowed down, sometimes not all assets will get copied. This creates non deterministicly faulty outputs for NestJS builds.

This means when you are for example building Docker image using BuildKit, which has parallel execution, a CPU and HDD intensive task of another Docker build step will cause part of your assets not being copied.

As a direct consequence part of your application will not be working as usual. Also as this not being a code part, it will probably not fail during startup and you will learn the hard way, e.g. users not being able to register, because the HTML file with validation email cannot be loaded.

This was discussed previously in #1828 and #749 and it was presumably caused by the timeout in assets manager on L26. Also the note on L25 actually suggests this could happen for large files.

public closeWatchers() {
// Consider adjusting this for larger files
const timeoutMs = 500;
const closeFn = () => {
if (this.actionInProgress) {
this.actionInProgress = false;
setTimeout(closeFn, timeoutMs);
} else {
this.watchers.forEach((watcher) => watcher.close());
}
};
setTimeout(closeFn, timeoutMs);
}

Minimum reproduction code

The issue seems the same as before and the reproduction code will be hard to create, as it is a concurrency issue with other processes. So would like to discuss if it's needed before coding.

Steps to reproduce

  1. Run NestJS build with either
    • lot of files
    • slow machine
    • machine slowed down with other parallel processes using HDD
  2. Random part of your assets will not make it to the build

Expected behavior

All assets must be in the build no matter the build time.

Package version

9.3.0

NestJS version

9.4.0

Node.js version

18.14.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

At least the timeoutMs should be configurable in nest-cli.json or somewhere, but I think by default the copy process should never be killed before finishing.

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