At least one legit memory leak, but also add a SIGTERM handler that attempts a clean shutdown so that I can ensure that it succeeds. It currently does not.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4793 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
01efc215fd
commit
2f83ecc1ac
@ -104,6 +104,7 @@ static JSValue _httpd_response_end(JSContext* context, JSValueConst this_val, in
|
||||
const char* headers[64] = { 0 };
|
||||
JSValue response_headers = JS_GetPropertyStr(context, this_val, "response_headers");
|
||||
int headers_count = _object_to_headers(context, response_headers, headers, tf_countof(headers));
|
||||
JS_FreeValue(context, response_headers);
|
||||
|
||||
tf_http_respond(request, status, headers, headers_count, data, length);
|
||||
|
||||
@ -302,11 +303,6 @@ static JSValue _httpd_websocket_upgrade(JSContext* context, JSValueConst this_va
|
||||
}
|
||||
headers_count += _object_to_headers(context, argv[1], headers + headers_count * 2, tf_countof(headers) - headers_count * 2);
|
||||
|
||||
for (int i = 0; i < headers_count; i += 2)
|
||||
{
|
||||
tf_printf("[%d] %s = %s\n", i / 2, headers[i * 2 + 0], headers[i * 2 + 1]);
|
||||
}
|
||||
|
||||
tf_http_request_websocket_upgrade(request);
|
||||
tf_http_respond(request, 101, headers, headers_count, NULL, 0);
|
||||
|
||||
|
22
src/task.c
22
src/task.c
@ -123,6 +123,7 @@ typedef struct _tf_task_t
|
||||
|
||||
uv_idle_t idle;
|
||||
uv_prepare_t prepare;
|
||||
uv_signal_t signal;
|
||||
|
||||
export_record_t** _exports;
|
||||
int _export_count;
|
||||
@ -1570,6 +1571,17 @@ JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name,
|
||||
return module;
|
||||
}
|
||||
|
||||
static void _tf_task_sigterm(uv_signal_t* signal, int sig)
|
||||
{
|
||||
tf_task_t* task = signal->data;
|
||||
task->_killed = true;
|
||||
if (task->_parent)
|
||||
{
|
||||
tf_packetstream_close(tf_taskstub_get_stream(task->_parent));
|
||||
}
|
||||
uv_stop(&task->_loop);
|
||||
}
|
||||
|
||||
tf_task_t* tf_task_create()
|
||||
{
|
||||
tf_task_t* task = tf_malloc(sizeof(tf_task_t));
|
||||
@ -1614,6 +1626,9 @@ tf_task_t* tf_task_create()
|
||||
uv_prepare_init(&task->_loop, &task->prepare);
|
||||
uv_unref((uv_handle_t*)&task->prepare);
|
||||
uv_idle_start(&task->idle, _tf_task_run_jobs_idle);
|
||||
task->signal.data = task;
|
||||
uv_signal_init(&task->_loop, &task->signal);
|
||||
uv_signal_start(&task->signal, _tf_task_sigterm, SIGTERM);
|
||||
return task;
|
||||
}
|
||||
|
||||
@ -1782,8 +1797,8 @@ void tf_task_destroy(tf_task_t* task)
|
||||
while (task->_children)
|
||||
{
|
||||
task_child_node_t* node = task->_children;
|
||||
tf_taskstub_destroy(node->stub);
|
||||
task->_children = node->next;
|
||||
tf_taskstub_destroy(node->stub);
|
||||
tf_free(node);
|
||||
}
|
||||
if (task->_parent)
|
||||
@ -1841,11 +1856,14 @@ void tf_task_destroy(tf_task_t* task)
|
||||
}
|
||||
uv_close((uv_handle_t*)&task->idle, _tf_task_on_handle_close);
|
||||
uv_close((uv_handle_t*)&task->prepare, _tf_task_on_handle_close);
|
||||
uv_signal_stop(&task->signal);
|
||||
uv_close((uv_handle_t*)&task->signal, _tf_task_on_handle_close);
|
||||
|
||||
while (task->trace_timer.data ||
|
||||
task->gc_timer.data ||
|
||||
task->idle.data ||
|
||||
task->prepare.data)
|
||||
task->prepare.data ||
|
||||
task->signal.data)
|
||||
{
|
||||
uv_run(&task->_loop, UV_RUN_ONCE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user