Gulp does not wait for gulpfile.js to complete when SIGTERM is sent to gulp-cli
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 408
- Fork
- 111
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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:
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:
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Il report cita gulpfile.js e il punto di ingresso di gulp-cli, ma non indica alcun file del repository né alcun test. Riproduci il caso SIGTERM con il gulpfile fornito, quindi traccia il modo in cui gulp-cli gestisce i segnali e attende il completamento del gulpfile. Il lavoro è completato quando l’input del terminale non viene restituito finché non sono terminati l’output della pulizia e il completamento del task gulp.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- cli
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100