Skip to content

Commit

Permalink
Add uncaught_exceptions check
Browse files Browse the repository at this point in the history
- Do not call CloseDatabase when uncaught_exceptions is not 0 in
  DatabaseEngine Destructor. This can avoid crash in sqllogictest.

Signed-off-by: Wenbo Li <[email protected]>
  • Loading branch information
hnjylwb committed Mar 15, 2024
1 parent 97bd04e commit 9b4e3a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/database/database_engine.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "database/database_engine.h"

#include <algorithm>
#include <exception>

#include "binder/binder.h"
#include "binder/statements/statements.h"
Expand Down Expand Up @@ -63,7 +63,7 @@ DatabaseEngine::DatabaseEngine() {

DatabaseEngine::~DatabaseEngine() {
// 如果数据库不是崩溃状态,关闭数据库
if (!crashed_) {
if (std::uncaught_exceptions() == 0 && !crashed_) {
CloseDatabase();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/storage/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void Disk::ReadPage(const std::string &path, pageid_t page_id, char *data) {
fs.seekg(page_id * DB_PAGE_SIZE);
fs.read(data, DB_PAGE_SIZE);
if (fs.gcount() != DB_PAGE_SIZE) {
throw DbException(path + " read page failed: read " + std::to_string(fs.gcount()) + " bytes, expected " +
std::to_string(DB_PAGE_SIZE) + " bytes");
throw DbException(path + " read page " + std::to_string(page_id) + " failed: read " + std::to_string(fs.gcount()) +
" bytes, expected " + std::to_string(DB_PAGE_SIZE) + " bytes");
}
}

Expand Down

0 comments on commit 9b4e3a6

Please sign in to comment.