Extra watcher doesn't get killed when shutting down phoenix

I added a gulp watcher in config, but the watcher process is still there after I shut down phoenix.

2 Likes

In other word, how does phoenix kill brunch watcher when it’s shut down? I searched “node” or “brunch” in src but didn’t find anything seems relevant.

1 Like

In theory those get started as a “port” and should die alltogether with their owning process.

Are you really shure, that the remaining process you see (I assume you used ps or similiar tooling) got created by the phoenix instance you just shut down?

Yes, I double checked. My friend told me that it’s because Gulp process ignore the EOF signal sent by Erlang when shutting down Phoenix so that’s why I guess.

The wrapper script here might help:

http://elixir-lang.org/docs/master/elixir/Port.html#module-zombie-processes

1 Like

https://hexdocs.pm/elixir/Port.html#module-zombie-processes

My Node is rusty. I wonder if something like this would work:

process.stdin.on('close', function() {
    process.exit(0);
});
3 Likes

Thanks. This approach did work.

1 Like

Yup, this is exactly what we used in Brunch (we sent a pull request for the --stdin option).

3 Likes

This approach didn’t seem to work for me in in Gulp.

Here’s the relevant code from gulpfile.js:

gulp.task('watch', ['scss', 'js', 'js-vendor', 'fonts', 'static'], function () {
  gulp.watch('css/**/*.scss', ['scss']);
  gulp.watch(Paths.JS, ['js']);
  process.stdin.on('close', function () {
    console.log('Exiting watcher');
    process.exit(0);
  });
}

I’ve also tried:

process.stdin.on('end')

But it doesn’t work either.

Any other thoughts?

you have to use older approach with process.stdin.resume();

const fs = require("fs");
const path = require("path");

const filePath = path.resolve(__dirname, "hello.txt");

process.stdin.on("end", () => {
  fs.writeFileSync(filePath, `Hello`);
});

process.stdin.resume();
2 Likes

Is there a fresh link for this wrapper script? I’m having this issue and this link now gives to a 404.

https://hexdocs.pm/elixir/Port.html#module-zombie-operating-system-processes

1 Like