diff --git a/src/ssb.c b/src/ssb.c index c34df246..38f2e22f 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -2565,6 +2565,11 @@ void tf_ssb_destroy(tf_ssb_t* ssb) } } +bool tf_ssb_is_shutting_down(tf_ssb_t* ssb) +{ + return ssb->shutting_down; +} + void tf_ssb_run(tf_ssb_t* ssb) { uv_run(ssb->loop, UV_RUN_DEFAULT); diff --git a/src/ssb.connections.c b/src/ssb.connections.c index 0e8def28..8ab356be 100644 --- a/src/ssb.connections.c +++ b/src/ssb.connections.c @@ -86,6 +86,10 @@ typedef struct _tf_ssb_connections_get_next_t static void _tf_ssb_connections_get_next_work(tf_ssb_t* ssb, void* user_data) { tf_ssb_connections_get_next_t* next = user_data; + if (tf_ssb_is_shutting_down(ssb)) + { + return; + } next->ready = _tf_ssb_connections_get_next_connection(next->connections, next->host, sizeof(next->host), &next->port, next->key, sizeof(next->key)); } @@ -159,6 +163,10 @@ typedef struct _tf_ssb_connections_update_t static void _tf_ssb_connections_update_work(tf_ssb_t* ssb, void* user_data) { tf_ssb_connections_update_t* update = user_data; + if (tf_ssb_is_shutting_down(ssb)) + { + return; + } sqlite3_stmt* statement; sqlite3* db = tf_ssb_acquire_db_writer(ssb); if (update->attempted) diff --git a/src/ssb.h b/src/ssb.h index 0be2401c..4e24980b 100644 --- a/src/ssb.h +++ b/src/ssb.h @@ -144,6 +144,13 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path */ void tf_ssb_destroy(tf_ssb_t* ssb); +/** +** Checking if the SSB instance is in the process of shutting down. +** @param ssb The SSB instance. +** @return true If the SSB instance is shutting down. +*/ +bool tf_ssb_is_shutting_down(tf_ssb_t* ssb); + /** ** Start optional periodic work. ** @param ssb The SSB instance.