Have we achieved clean shutdown?

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4841 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-13 23:07:36 +00:00
parent e7791d38ff
commit 685754895b
6 changed files with 84 additions and 75 deletions

View File

@ -2376,8 +2376,12 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{
tf_printf("tf_ssb_destroy\n");
ssb->shutting_down = true;
tf_ssb_connections_destroy(ssb->connections_tracker);
ssb->connections_tracker = NULL;
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))
{
@ -2489,19 +2493,11 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
tf_free(node);
}
tf_printf("rpc=%p conn_changed=%p mess_add=%p blob_want_add=%p broadcast_change=%p\n",
ssb->rpc,
ssb->connections_changed,
ssb->message_added,
ssb->blob_want_added,
ssb->broadcasts_changed);
tf_printf("Closing connections.\n");
tf_ssb_connection_t* connection = ssb->connections;
while (connection)
{
tf_ssb_connection_t* next = connection->next;
tf_printf("close %p\n", connection);
tf_ssb_connection_close(connection);
connection = next;
}
@ -2515,13 +2511,18 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
tf_printf("uv_loop_close: %s\n", uv_strerror(r));
}
}
tf_printf("loop closed\n");
tf_printf("uv loop closed.\n");
if (ssb->own_context)
{
JS_FreeContext(ssb->context);
JS_FreeRuntime(ssb->runtime);
ssb->own_context = false;
}
if (ssb->db_writer)
{
sqlite3_close(ssb->db_writer);
ssb->db_writer = NULL;
}
sqlite3_close(ssb->db_writer);
while (ssb->broadcasts)
{
tf_ssb_broadcast_t* broadcast = ssb->broadcasts;
@ -2540,17 +2541,28 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
{
sqlite3_close(ssb->db_readers[i]);
}
tf_free(ssb->db_readers);
tf_printf("destroying mutexes\n");
uv_mutex_destroy(&ssb->db_readers_lock);
uv_mutex_destroy(&ssb->db_writer_lock);
tf_printf("mutexes destroyed\n");
tf_free((void*)ssb->db_path);
tf_free(ssb->room_name);
ssb->room_name = NULL;
ssb->db_readers_count = 0;
if (ssb->db_readers)
{
tf_free(ssb->db_readers);
ssb->db_readers = NULL;
}
if (ssb->db_path)
{
tf_free((void*)ssb->db_path);
ssb->db_path = NULL;
}
if (ssb->room_name)
{
tf_free(ssb->room_name);
ssb->room_name = NULL;
}
if (ssb->connection_ref_count == 0)
{
uv_mutex_destroy(&ssb->db_readers_lock);
uv_mutex_destroy(&ssb->db_writer_lock);
tf_free(ssb);
}
}