Skip to content

Commit

Permalink
Terminate webpack dev server process only on connection error (#6520)
Browse files Browse the repository at this point in the history
Try to reconnect always on connection close. So the process is
terminated only if there is a connection error (which happens if there
is no network port available which is listen by Java process).

Fixes vaadin/spring#494
  • Loading branch information
Denis committed Sep 23, 2019
1 parent 19b9d92 commit d73676e
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions flow-server/src/main/resources/webpack.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,27 @@ if (watchDogPort){

const net = require('net');

function setupWatchDog(firstRun){
function setupWatchDog(){
var client = new net.Socket();
client.connect(watchDogPort, 'localhost', function() {
if (firstRun){
console.debug('Watchdog connected.');
} else {
console.log('Watchdog connected.');
}
console.debug('Watchdog connected.');
});

client.on('error', function(){
console.error("Watchdog connection error. Terminating webpack process...");
console.log("Watchdog connection error. Terminating webpack process...");
client.destroy();
process.exit(0);
});

client.on('close', function() {
client.destroy();
if (firstRun){
console.debug('Watchdog connection closed. Trying to re-run watchdog.');
setupWatchDog(false);
}
else {
console.log('Watchdog connection closed. Terminating webpack process...');
process.exit(0);
}
console.debug('Watchdog connection closed. Trying to re-run watchdog.');
setupWatchDog();
});
}

if (watchDogPort){
setupWatchDog(true);
setupWatchDog();
}


Expand Down

0 comments on commit d73676e

Please sign in to comment.