Ever closer to the elusive clean http shutdown.

This commit is contained in:
Cory McWilliams 2024-03-25 16:23:45 -04:00
parent 15c9f8f458
commit 610e756c07

View File

@ -161,10 +161,11 @@ static void _http_request_destroy(tf_http_request_t* request)
tf_http_close_callback* on_close = request->on_close; tf_http_close_callback* on_close = request->on_close;
if (on_close) if (on_close)
{ {
tf_trace_t* trace = request->http->trace;
request->on_close = NULL; request->on_close = NULL;
tf_trace_begin(request->http->trace, request->connection && request->connection->trace_name ? request->connection->trace_name : "websocket"); tf_trace_begin(trace, request->connection && request->connection->trace_name ? request->connection->trace_name : "websocket");
on_close(request); on_close(request);
tf_trace_end(request->http->trace); tf_trace_end(trace);
} }
} }
@ -174,12 +175,9 @@ static void _http_connection_destroy(tf_http_connection_t* connection, const cha
if (connection->request) if (connection->request)
{ {
_http_request_destroy(connection->request); tf_http_request_t* request = connection->request;
if (connection->request && connection->request->ref_count == 0)
{
tf_free(connection->request);
}
connection->request = NULL; connection->request = NULL;
_http_request_destroy(request);
} }
if (connection->tcp.data && !uv_is_closing((uv_handle_t*)&connection->tcp)) if (connection->tcp.data && !uv_is_closing((uv_handle_t*)&connection->tcp))
@ -965,11 +963,11 @@ void tf_http_request_unref(tf_http_request_t* request)
tf_http_connection_t* connection = request->connection; tf_http_connection_t* connection = request->connection;
if (--request->ref_count == 0) if (--request->ref_count == 0)
{ {
_http_request_destroy(request);
if (connection) if (connection)
{ {
connection->request = NULL; connection->request = NULL;
} }
_http_request_destroy(request);
tf_free(request); tf_free(request);
} }