Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
This is brute-force fix:

1. try stopping cate service, timeout 2.5 secs
2. on timeout, unconditionally send SIGKILL
  • Loading branch information
forman authored and forman committed Mar 22, 2018
1 parent a14651c commit 53f02ad
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ const WEBAPI_LOG_PREFIX = 'cate-webapi:';
const ERRCODE_WEBAPI_INTERNAL_ERROR = 1;
const ERRCODE_WEBAPI_TIMEOUT = 2;
const ERRCODE_WEBAPI_NO_FREE_PORT = 3;
const ERRCODE_OFFSET_WEBAPI_BAD_EXIT = 4000;
const ERRCODE_SETUP_FAILED = 5;

// Timeout for starting WebAPI in seconds.
// See https://github.com/CCI-Tools/cate/issues/550
const WEBAPI_START_TIMEOUT_MAX = 60;

// Timeout for stopping WebAPI in seconds.
const WEBAPI_STOP_TIMEOUT_MAX = 1;
const WEBAPI_STOP_TIMEOUT_MAX = 2.5;

// WebAPI access timeout in seconds:
const WEBAPI_ACCESS_TIMEOUT_MAX = 0.5;
Expand All @@ -47,7 +46,7 @@ const WEBAPI_ACCESS_TIMEOUT_MAX = 0.5;
const WEBAPI_ACCESS_DELAY_MAX = 0.5;

// Signal used to kill a running WebAPI service if a stop requiest times out:
const WEBAPI_KILL_SIGNAL = "SIGTERM";
const WEBAPI_KILL_SIGNAL = "SIGKILL";


const NANOS_PER_SEC = 1.0e9;
Expand Down Expand Up @@ -387,12 +386,15 @@ class CateDesktopApp {
log.info(`Stopping Cate service: ${webAPIStopCommand}`);
// this must be sync to make sure the stop is performed before this process ends
const processData = child_process.spawnSync(webAPIStopCommand,[],
{...this.webAPIProcessOptions, timeout: 1000 * this.webAPIStopTimeout});
{
...this.webAPIProcessOptions,
timeout: 1000 * this.webAPIStopTimeout
});
if (processData.status !== 0 || processData.error) {
log.error(`Failed to stop Cate service. Status: ${processData.status}, ${processData.error}`);
log.warn(`Killing it (pid=${this.webAPIProcess.pid})...`);
log.warn(`Killing it (pid=${this.webAPIProcess.pid}), sending ${this.webAPIKillSignal}...`);
this.webAPIProcess.kill(this.webAPIKillSignal);
this.webAPIProcess = null;
//this.webAPIProcess = null;
//sleep(10000);
//log.error("Still alive!");
}
Expand Down Expand Up @@ -777,9 +779,11 @@ function findFreePort(fromPort?: number, toPort?: number, callback?: (port: numb
findPort(fromPort);
}

/*
function sleep(time: number) {
const stop = new Date().getTime();
while(new Date().getTime() < stop + time) {
;
}
}
*/

0 comments on commit 53f02ad

Please sign in to comment.