ssb: Shutdown fixes.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 16m12s

This commit is contained in:
2024-11-25 17:14:16 -05:00
parent a08bba438e
commit 71444b0427
3 changed files with 29 additions and 7 deletions

View File

@ -220,6 +220,7 @@ typedef struct _tf_ssb_t
bool verbose;
bool store_debug_messages;
bool shutting_down;
bool shutting_down_deferred;
int messages_stored;
int blobs_stored;
@ -2009,7 +2010,7 @@ static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const ch
connection->debug_messages[i] = NULL;
}
if (--connection->ssb->connection_ref_count == 0 && connection->ssb->shutting_down)
if (--connection->ssb->connection_ref_count == 0 && connection->ssb->shutting_down_deferred)
{
tf_ssb_destroy(connection->ssb);
}
@ -2516,12 +2517,6 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
tf_printf("tf_ssb_destroy\n");
ssb->shutting_down = true;
if (ssb->connections_tracker)
{
tf_ssb_connections_destroy(ssb->connections_tracker);
ssb->connections_tracker = NULL;
}
if (ssb->broadcast_listener.data && !uv_is_closing((uv_handle_t*)&ssb->broadcast_listener))
{
uv_close((uv_handle_t*)&ssb->broadcast_listener, _tf_ssb_on_handle_close);
@ -2637,10 +2632,20 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
tf_ssb_connection_close(connection);
connection = next;
}
uv_run(ssb->loop, UV_RUN_NOWAIT);
tf_printf("Closed.\n");
if (ssb->connections_tracker)
{
tf_ssb_connections_destroy(ssb->connections_tracker);
ssb->connections_tracker = NULL;
}
uv_run(ssb->loop, UV_RUN_NOWAIT);
if (ssb->loop == &ssb->own_loop)
{
tf_printf("uv_loop_close\n");
int r = uv_loop_close(ssb->loop);
if (r != 0)
{
@ -2695,6 +2700,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
ssb->room_name = NULL;
}
ssb->shutting_down_deferred = true;
if (ssb->connection_ref_count == 0)
{
uv_mutex_destroy(&ssb->db_readers_lock);