Skip to content

Improve lingering processes warning logic #1888

@ehmicky

Description

@ehmicky

Background

When users build command or Build plugins create background processes, but forget to terminate them before exit, those processes will keep running until the container exits. This is a user error (bad cleanup) and we print a warning message when this happens.

https://github.com/netlify/build-image/blob/450c24b893036c2813a0b0d0a2a05bcdd81935a4/run-build-functions.sh#L780-L798

As part of the onSuccess feature, we are moving this logic to Netlify Build (see https://github.com/netlify/buildbot/issues/928). Using Node.js allows us more flexibility, so this might be a good time to improve the underlying logic of this warning message.

Problem

There are several issues with the current logic, which relies on listing the processes then excluding a hard-coded list of processes known to run in our buildbot:

  • It relies on a hard-coded list of known processes, which is brittle. Any new process spawned in our buildbot is likely to break that logic.
  • It does not work in CLI builds
  • It is slow: it spawns almost 10 different processes, serially
  • The output of ps aux is too verbose, making the problem unclear for our users

Solution

I believe the following solution would fix the problems above.

We should list all processes right before the build command and Build plugins are run. We should then do it again right after the build command and Build plugins have completed. We should compute the difference: any process which is then running and was not running before should be reported as a lingering process.

We could also run the above logic both before/after the build command and before/after the build command + Build plugins. Like this, we will know whether the lingering process was created by the build command or by a Build plugin, which we can report to the user, helping them fix the problem.

Related issues

Instead of using Unix utilities, we should also rely on Node.js core APIs and libraries (see #1966).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions