@cryptotaxi247 / netdata-1 / commits / 6e9de1462

Reset database connection handle on close (#17266)

* Set database to NULL on close * Serialize sqlite_library_shutdown

Stelios Fragkakis committed Mar 27, 2024 at 09:33 UTC 6e9de14621bb2721fb468b76a93c9eee7c0b318a
1 file changed +5
src/database/sqlite/sqlite_functions.c
+5
@@ -346,6 +346,7 @@ void sql_close_database(sqlite3 *database, const char *database_name)
346 rc = sqlite3_close_v2(database);
347 if (unlikely(rc != SQLITE_OK))
348 error_report("%s: Error while closing the sqlite database: rc %d, error \"%s\"", database_name, rc, sqlite3_errstr(rc));
349 + database = NULL;
350 }
351
352 extern sqlite3 *db_context_meta;
@@ -367,7 +368,11 @@ int sqlite_library_init(void)
368 return (SQLITE_OK != rc);
369 }
370
371 +SPINLOCK sqlite_spinlock = NETDATA_SPINLOCK_INITIALIZER;
372 +
373 void sqlite_library_shutdown(void)
374 {
375 + spinlock_lock(&sqlite_spinlock);
376 (void) sqlite3_shutdown();
377 + spinlock_unlock(&sqlite_spinlock);
378 }