Skip to content

Commit

Permalink
Fix stopping trace server during shutdown
Browse files Browse the repository at this point in the history
Fixes eclipse-cdt-cloud#13

Signed-off-by: Bernd Hufmann <[email protected]>
  • Loading branch information
bhufmann committed Aug 23, 2023
1 parent 0fceb92 commit 2cb84e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function activate(context: vscode.ExtensionContext) {
activation = context;
}

export function deactivate() {
server.stopOrReset(activation);
export async function deactivate() {
await server.shutdown(activation);
}

function registerStopOrReset(context: vscode.ExtensionContext | undefined): vscode.Disposable {
Expand Down
22 changes: 21 additions & 1 deletion src/trace-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const millis = 10000;
const none = -1;
const prefix = 'Trace Server';
const suffix = ' failure or so.';
const SHUTDOWN_DELAY = 2000;

export class TraceServer {
private server: ChildProcess | undefined;
Expand Down Expand Up @@ -71,11 +72,30 @@ export class TraceServer {
this.server = undefined;
}

async shutdown(context: vscode.ExtensionContext) {
// Take the pid from the server instead from workspace state because
// during shutdown the workspace can't be queried anymore
const pid = this.server ? this.server.pid : undefined;
if (!pid) {
return;
}
if (pid) {
treeKill(pid);
// Allow the treeKill to finish collecting and killing all
// spawned processes.
await new Promise(resolve => setTimeout(resolve, SHUTDOWN_DELAY));

// Try to reset pid in workspace state
await context?.workspaceState.update(key, none);
}
}

async startIfStopped(context: vscode.ExtensionContext | undefined) {

const pid = context?.workspaceState.get(key);
console.log("Pid: " + pid);
const stopped = !pid || pid === none;
const foreigner = await this.isUp();

if (stopped && !foreigner) {
await this.start(context);
} else if (foreigner) {
Expand Down

0 comments on commit 2cb84e0

Please sign in to comment.