From 72e1b2025c3217a38edb850728dec7cf5a22df23 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 4 Jun 2025 19:47:54 -0400 Subject: [PATCH] core: Chasing shutdown issues some more. Logging. No more task promises once shutdown starts. #108 --- src/http.c | 5 +++++ src/task.c | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/http.c b/src/http.c index ae8d1220..93074c0d 100644 --- a/src/http.c +++ b/src/http.c @@ -813,6 +813,11 @@ void tf_http_destroy(tf_http_t* http) return; } + if (!http->is_shutting_down) + { + tf_printf("tf_http_destroy\n"); + } + http->is_shutting_down = true; http->is_in_destroy = true; diff --git a/src/task.c b/src/task.c index 0526efbc..0f76996f 100644 --- a/src/task.c +++ b/src/task.c @@ -1301,19 +1301,19 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise) JS_FreeValue(task->_context, error); } - promiseid_t promiseId; + promiseid_t promise_id; do { - promiseId = task->_nextPromise++; - } while (_tf_task_find_promise(task, promiseId) || !promiseId); + promise_id = task->_nextPromise++; + } while (_tf_task_find_promise(task, promise_id) || !promise_id); promise_t promise = { - .id = promiseId, + .id = promise_id, .values = { JS_NULL, JS_NULL }, .stack_hash = stack_hash, }; JSValue result = JS_NewPromiseCapability(task->_context, promise.values); - int index = tf_util_insert_index((void*)(intptr_t)promiseId, task->_promises, task->_promise_count, sizeof(promise_t), _promise_compare); + int index = tf_util_insert_index((void*)(intptr_t)promise_id, task->_promises, task->_promise_count, sizeof(promise_t), _promise_compare); task->_promises = tf_resize_vec(task->_promises, sizeof(promise_t) * (task->_promise_count + 1)); if (task->_promise_count - index) { @@ -1321,7 +1321,12 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise) } task->_promises[index] = promise; task->_promise_count++; - *out_promise = promiseId; + *out_promise = promise_id; + + if (task->_shutting_down) + { + tf_task_reject_promise(task, promise_id, JS_ThrowInternalError(task->_context, "Shutting down")); + } return result; } @@ -1383,7 +1388,7 @@ static void _promise_release_for_task(tf_task_t* task, taskid_t task_id) const promise_t* promise = &task->_promises[i]; if (promise->task == task_id) { - tf_task_reject_promise(task, promise->id, JS_ThrowInternalError(task->_context, "Task is gone.")); + tf_task_reject_promise(task, promise->id, JS_ThrowInternalError(task->_context, "Task is gone")); more = true; } } @@ -1819,6 +1824,11 @@ JSValue tf_taskstub_kill(tf_taskstub_t* stub); void tf_task_destroy(tf_task_t* task) { + if (!task->_shutting_down) + { + tf_printf("tf_task_destroy\n"); + } + task->_shutting_down = true; while (task->_children)