From df0bb102dcad9e7115ed1a6d17bf2044cfe32635 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 21 Jan 2022 00:49:03 +0000 Subject: [PATCH] Kill tasks when their websocket closes. Sigh. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3779 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/app.js | 14 +++++++++++++- core/httpd.js | 4 ++++ src/taskstub.js.c | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/core/app.js b/core/app.js index b51ef753..7c34b808 100644 --- a/core/app.js +++ b/core/app.js @@ -38,6 +38,18 @@ function socket(request, response, client) { var options = {}; var credentials = auth.query(request.headers); + response.onClose = async function() { + if (process && process.task) { + process.task.kill(); + } + } + + response.onError = async function(error) { + if (process && process.task) { + process.task.kill(); + } + } + response.onMessage = async function(event) { if (event.opCode == 0x1 || event.opCode == 0x2) { var message; @@ -110,7 +122,7 @@ function socket(request, response, client) { } } else if (event.opCode == 0x8) { // Close. - if (process) { + if (process && process.task) { process.task.kill(); } response.send(event.data, 0x8); diff --git a/core/httpd.js b/core/httpd.js index fb461988..c1bae69b 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -301,10 +301,14 @@ function handleWebSocketRequest(request, response, client) { break; } } + } else { + response.onClose(); + client.close(); } }); client.onError(function(error) { logError(client.peerName + " - - [" + new Date() + "] " + error); + response.onError(error); }); let headers = { diff --git a/src/taskstub.js.c b/src/taskstub.js.c index 9caa9916..212a5261 100644 --- a/src/taskstub.js.c +++ b/src/taskstub.js.c @@ -286,7 +286,7 @@ static JSValue _taskstub_getExports(JSContext* context, JSValueConst this_val, i tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId); promiseid_t promise = -1; JSValue result = tf_task_allocate_promise(stub->_owner, &promise); - tf_task_send_promise_message(stub->_owner, (tf_taskstub_t*)stub, kGetExports, promise, JS_UNDEFINED); + tf_task_send_promise_message(stub->_owner, stub, kGetExports, promise, JS_UNDEFINED); return result; } @@ -369,7 +369,7 @@ static JSValue _taskstub_execute(JSContext* context, JSValueConst this_val, int tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId); promiseid_t promise = -1; JSValue result = tf_task_allocate_promise(stub->_owner, &promise); - tf_task_send_promise_message(stub->_owner, (tf_taskstub_t*)stub, kExecute, promise, argv[0]); + tf_task_send_promise_message(stub->_owner, stub, kExecute, promise, argv[0]); return result; }