Gulp does not wait for gulpfile.js to complete when SIGTERM is sent to gulp-cli
- Vorherrschende Sprache
- JavaScript
- Sterne
- 408
- Forks
- 112
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### What were you expecting to happen?
When I click CTRL+C, a sigterm is sent to gulp. I have created a watcher which spawns a child_process when anything under `src/**` is triggered. to ensure that the instance has fully exited before we restart a new instance. My instance has some async cleanup (~50 ms). I've added an `exitHandle` for SIGINT and SIGTERM handler to my gulpfile.js to prevent the process from exiting immediately. When this completes properly, there are some console logs, and then the user should be given the terminal after a short delay.
### What actually happened?
Gulpfile completes, but gulp-cli has exited. This results in losing the current process losing the terminal input. (eg `KleptoKat@Computer:~/app$`) with the console outputs after this line. It requires an extra enter keypress which is not a huge deal but it's a little annoying.
### Please give us a sample of your gulpfile
Here is a smaller gulpfile:
```js
const gulp = require('gulp');
const { spawn } = require('child_process');
const { EventEmitter } = require('events');
let instance;
let instanceRunning = false;
let instanceChanged = new EventEmitter();
let watchCb;
function startAll(cb) {
instance = spawn('node', [ '-e', '"setTimeout(() => {}, 20000)"'], {
stdio: [undefined, process.stdout, process.stderr],
env: process.env,
detached: true,
});
instanceRunning = true;
instanceChanged.emit('started');
instance.addListener('exit', (code) => {
console.log(`Instance exited with code ${ code }`);
instanceRunning = false;
instance = undefined;
instanceChanged.emit('stopped');
if (code === 10) {
startAll();
}
})
if (cb) { cb() };
}
function kill(cb) {
if (instance) {
console.log(`Killing instance...`);
const onStopped = () => {
instanceChanged.removeListener('stopped', onStopped);
cb();
}
instanceChanged.addListener('stopped', onStopped);
instance.kill();
} else {
cb();
}
}
function watch(cb) {
// TODO: restart individual services w/hot reload :O
gulp.watch('src/**/*', gulp.series(
'build',
'kill',
'startAll'
));
watchCb = cb;
}
gulp.task('kill', kill);
gulp.task('startAll', startAll);
gulp.task('build', buildSrc);
gulp.task('watch', watch);
gulp.task('default', gulp.series(
'build',
'startAll',
'watch',
'kill'
));
function exitHandle(signal) {
console.log('Exit handle', signal. instanceRunning);
if (watchCb) {
watchCb();
} else {
process.exit(0);
}
setTimeout(() => {}, 50000);
if (instance) {
instance.kill();
} else {
}
}
process.on('SIGINT', exitHandle);
process.on('SIGTERM', exitHandle);
process.on('SIGHUP', exitHandle);
```
### Terminal output / screenshots
When CTRL C is entered:
```sh
INFO SERVER: Gateway started on port 1337
^CExit handle undefined
[18:09:20] Finished 'watch' after 2 min
[18:09:20] Starting 'kill'...
Killing instance...
INFO BrokerManager: Stopping
KleptoKat@Computer:~/app$ INFO broker: ServiceBroker is stopped. Good bye.
INFO BrokerManager: stopped
Instance exited with code 0
[18:09:20] Finished 'kill' after 26 ms
[18:09:20] Finished 'default' after 2.1 min
[ ENTER KEY IS PRESSED HERE ]
KleptoKat@Computer:~/app$
```
### Please provide the following information:
* OS & version [e.g. MacOS Catalina 10.15.4]: Ubuntu 20
* node version (run `node -v`): v10.16.3
* npm version (run `npm -v`): 6.9.0
* gulp version (run `gulp -v`): CLI 2.2, local 4.0.2
I can help provide a more replicable environment if need be. It's just slightly annoying. A possible fix may be to add an argument, like --waitForGulpfileToExit which will enable this kind of waiting behaviour.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Der Bericht nennt gulpfile.js und den gulp-cli-Einstiegspunkt, aber keine Repository-Datei und keinen Test. Reproduziere den SIGTERM-Fall mit der bereitgestellten gulpfile und verfolge dann, wie gulp-cli Signale verarbeitet und auf den Abschluss der gulpfile wartet. Als abgeschlossen gilt die Arbeit, wenn die Terminaleingabe erst zurückgegeben wird, nachdem die Bereinigungsausgabe und der Abschluss der gulp task erfolgt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, node.js
- Bereich
- cli
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100