core: Chasing shutdown issues some more. Logging. No more task promises once shutdown starts. #108
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled

This commit is contained in:
Cory McWilliams 2025-06-04 19:47:54 -04:00
parent fc7c4b1257
commit 72e1b2025c
2 changed files with 22 additions and 7 deletions

View File

@ -813,6 +813,11 @@ void tf_http_destroy(tf_http_t* http)
return; return;
} }
if (!http->is_shutting_down)
{
tf_printf("tf_http_destroy\n");
}
http->is_shutting_down = true; http->is_shutting_down = true;
http->is_in_destroy = true; http->is_in_destroy = true;

View File

@ -1301,19 +1301,19 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
JS_FreeValue(task->_context, error); JS_FreeValue(task->_context, error);
} }
promiseid_t promiseId; promiseid_t promise_id;
do do
{ {
promiseId = task->_nextPromise++; promise_id = task->_nextPromise++;
} while (_tf_task_find_promise(task, promiseId) || !promiseId); } while (_tf_task_find_promise(task, promise_id) || !promise_id);
promise_t promise = { promise_t promise = {
.id = promiseId, .id = promise_id,
.values = { JS_NULL, JS_NULL }, .values = { JS_NULL, JS_NULL },
.stack_hash = stack_hash, .stack_hash = stack_hash,
}; };
JSValue result = JS_NewPromiseCapability(task->_context, promise.values); 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)); task->_promises = tf_resize_vec(task->_promises, sizeof(promise_t) * (task->_promise_count + 1));
if (task->_promise_count - index) 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->_promises[index] = promise;
task->_promise_count++; 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; 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]; const promise_t* promise = &task->_promises[i];
if (promise->task == task_id) 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; more = true;
} }
} }
@ -1819,6 +1824,11 @@ JSValue tf_taskstub_kill(tf_taskstub_t* stub);
void tf_task_destroy(tf_task_t* task) void tf_task_destroy(tf_task_t* task)
{ {
if (!task->_shutting_down)
{
tf_printf("tf_task_destroy\n");
}
task->_shutting_down = true; task->_shutting_down = true;
while (task->_children) while (task->_children)