From 66ed2150c53909e3f0cbfeaa98ed81144397a33c Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Wed, 20 Dec 2017 23:53:30 +0100 Subject: [PATCH] Close WebSockets explicitly Signed-off-by: Stefan Marr --- tools/kompos/src/vm-connection.ts | 12 +++++++++++- tools/kompos/tests/test-setup.ts | 14 +++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/kompos/src/vm-connection.ts b/tools/kompos/src/vm-connection.ts index b0c773a3d..1057215fa 100644 --- a/tools/kompos/src/vm-connection.ts +++ b/tools/kompos/src/vm-connection.ts @@ -119,7 +119,17 @@ export class VmConnection { } public disconnect() { - console.assert(this.isConnected()); + if (this.socket) { + try { + this.socket.terminate(); + } catch (_) { } + } + + if (this.traceDataSocket) { + try { + this.traceDataSocket.terminate(); + } catch (_) { } + } } public requestProgramInfo() { diff --git a/tools/kompos/tests/test-setup.ts b/tools/kompos/tests/test-setup.ts index 584dfd900..59d989e8d 100644 --- a/tools/kompos/tests/test-setup.ts +++ b/tools/kompos/tests/test-setup.ts @@ -155,17 +155,13 @@ export class TestConnection extends VmConnection { } public close(done: MochaDone) { - if (this.closed) { - done(); - return; + if (!this.closed) { + this.closed = true; + this.disconnect(); + this.somProc.kill(); } - this.somProc.on("exit", _code => { - this.closed = true; - // wait until process is shut down, to make sure all ports are closed - done(); - }); - this.somProc.kill(); + done(); } }