diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 0002e1c2e9aaa8d..23caac7d383df87 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -287,7 +287,6 @@ class BackupJob : public ThreadPoolWork { } } - private: void Cleanup() { if (pBackup_) { sqlite3_backup_finish(pBackup_); @@ -299,7 +298,7 @@ class BackupJob : public ThreadPoolWork { } } - // https://github.com/nodejs/node/blob/649da3b8377e030ea7b9a1bc0308451e26e28740/src/crypto/crypto_keygen.h#L126 + private: int backup_status_; Environment* env() const { return env_; } sqlite3* pDest_; @@ -459,6 +458,7 @@ void DatabaseSync::DeleteSessions() { DatabaseSync::~DatabaseSync() { if (IsOpen()) { FinalizeStatements(); + FinalizeBackups(); DeleteSessions(); sqlite3_close_v2(connection_); connection_ = nullptr; @@ -521,6 +521,14 @@ bool DatabaseSync::Open() { return true; } +void DatabaseSync::FinalizeBackups() { + for (auto backup : backups_) { + backup->Cleanup(); + } + + backups_.clear(); +} + void DatabaseSync::FinalizeStatements() { for (auto stmt : statements_) { stmt->Finalize(); @@ -825,6 +833,7 @@ void DatabaseSync::Backup(const FunctionCallbackInfo& args) { BackupJob* job = new BackupJob( env, db, resolver, source_db, *destFilename, dest_db, rate, progressFunc); + db->backups_.insert(job); job->ScheduleBackup(); } diff --git a/src/node_sqlite.h b/src/node_sqlite.h index 4b70be6b14ec956..e8628e72333eb97 100644 --- a/src/node_sqlite.h +++ b/src/node_sqlite.h @@ -43,6 +43,7 @@ class DatabaseOpenConfiguration { }; class StatementSync; +class BackupJob; class DatabaseSync : public BaseObject { public: @@ -65,6 +66,7 @@ class DatabaseSync : public BaseObject { const v8::FunctionCallbackInfo& args); static void LoadExtension(const v8::FunctionCallbackInfo& args); void FinalizeStatements(); + void FinalizeBackups(); void UntrackStatement(StatementSync* statement); bool IsOpen(); sqlite3* Connection(); @@ -82,7 +84,7 @@ class DatabaseSync : public BaseObject { bool enable_load_extension_; sqlite3* connection_; - std::set backups_; + std::set backups_; std::set sessions_; std::unordered_set statements_;