1
0
Fork 0
forked from lthn/blockchain

added proper handling mutex operating in lmdb, improved wallet backend error handling

This commit is contained in:
cryptozoidberg 2019-06-06 23:08:21 +03:00
parent 90c96228a3
commit b55c30337b
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
2 changed files with 13 additions and 5 deletions

View file

@ -11,6 +11,8 @@
#define BUF_SIZE 1024
#define CHECK_AND_ASSERT_MESS_LMDB_DB(rc, ret, mess) CHECK_AND_ASSERT_MES(res == MDB_SUCCESS, ret, "[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess);
#define CHECK_AND_ASSERT_THROW_MESS_LMDB_DB(rc, mess) CHECK_AND_ASSERT_THROW_MES(res == MDB_SUCCESS, "[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess);
#define ASSERT_MES_AND_THROW_LMDB(rc, mess) ASSERT_MES_AND_THROW("[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess);
#undef LOG_DEFAULT_CHANNEL
#define LOG_DEFAULT_CHANNEL "lmdb"
@ -134,7 +136,13 @@ namespace tools
CHECK_AND_ASSERT_THROW_MES(m_penv, "m_penv==null, db closed");
res = mdb_txn_begin(m_penv, pparent_tx, flags, &p_new_tx);
CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_txn_begin");
if(res != MDB_SUCCESS)
{
//Important: if mdb_txn_begin is failed need to unlock previously locked mutex
CRITICAL_SECTION_UNLOCK(m_write_exclusive_lock);
//throw exception to avoid regular code execution
ASSERT_MES_AND_THROW_LMDB(res, "Unable to mdb_txn_begin");
}
rtxlist.push_back(tx_entry());
rtxlist.back().count = read_only ? 1 : 0;

View file

@ -1565,18 +1565,18 @@ void daemon_backend::wallet_vs_options::worker_func()
catch (const std::exception& e)
{
LOG_PRINT_L0(w->get()->get_log_prefix() + "Failed to refresh wallet: " << e.what());
LOG_ERROR(w->get()->get_log_prefix() + " Exception in wallet handler: " << e.what());
wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_error;
pview->update_wallet_status(wsi);
return;
continue;
}
catch (...)
{
LOG_PRINT_L0(w->get()->get_log_prefix() + "Failed to refresh wallet, unknownk exception");
LOG_ERROR(w->get()->get_log_prefix() + " Exception in wallet handler: unknownk exception");
wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_error;
pview->update_wallet_status(wsi);
return;
continue;
}
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
}