From 71444b04274e9f8e09a2f51dce9cd921054c2b6a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 25 Nov 2024 17:14:16 -0500 Subject: [PATCH] ssb: Shutdown fixes. --- metadata/en-US/changelogs/30.txt | 12 ++++++++++++ src/ssb.c | 20 +++++++++++++------- src/ssb.connections.c | 4 ++++ 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 metadata/en-US/changelogs/30.txt diff --git a/metadata/en-US/changelogs/30.txt b/metadata/en-US/changelogs/30.txt new file mode 100644 index 000000000..18d4d5d40 --- /dev/null +++ b/metadata/en-US/changelogs/30.txt @@ -0,0 +1,12 @@ +* Improve, test, and fix some first time flow issues. +* Show reasons for failing to connect. +* Actually use CommonMark JS in "safe" mode(!). +* Move app blob handling from JS to C. +* Fixed "publish" command-line interface and used it to add a script that posts development activity updates. +* Minor style improvements. +* Make it possible to see the little graphs on mobile. +* Updated dependencies: + * libbacktrace + * CodeMirror + * c-ares 1.34.3 + * speedscope 1.21.0 diff --git a/src/ssb.c b/src/ssb.c index 3d8b7b35b..0ab4c8595 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -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); diff --git a/src/ssb.connections.c b/src/ssb.connections.c index 3bafe51e9..185dff285 100644 --- a/src/ssb.connections.c +++ b/src/ssb.connections.c @@ -112,6 +112,10 @@ static void _tf_ssb_connections_get_next_after_work(tf_ssb_t* ssb, int status, v static void _tf_ssb_connections_timer(uv_timer_t* timer) { tf_ssb_connections_t* connections = timer->data; + if (tf_ssb_is_shutting_down(connections->ssb)) + { + return; + } tf_ssb_connection_t* active[4]; int count = tf_ssb_get_connections(connections->ssb, active, tf_countof(active)); if (count < tf_countof(active))