Merge #15297: wallet: Releases dangling files on BerkeleyEnvironment::Close
d3bf3b930
qa: Test .walletlock file is closed (João Barbosa)2f8b8f479
wallet: Close wallet env lock file (João Barbosa)8602a1e6a
wallet: Close dbenv error file db.log (João Barbosa) Pull request description: This PR closes `db.log` and removes `.walletlock` files when `BerkeleyEnvironment` is closed. Fixes https://github.com/bitcoin/bitcoin/issues/15291#issuecomment-459131886. Tree-SHA512: 05d8b027feea914e0ba873e75d117857473d1fd7b400e41bd473d638171fa39d5be048990bf685dc0807f7d92418579b763056dc2a6dcf6b96777d5688ddee04
This commit is contained in:
commit
30e799a5f7
4 changed files with 22 additions and 0 deletions
|
@ -111,6 +111,12 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
|
|||
return true;
|
||||
}
|
||||
|
||||
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(cs_dir_locks);
|
||||
dir_locks.erase((directory / lockfile_name).string());
|
||||
}
|
||||
|
||||
void ReleaseDirectoryLocks()
|
||||
{
|
||||
std::lock_guard<std::mutex> ulock(cs_dir_locks);
|
||||
|
|
|
@ -70,6 +70,7 @@ int RaiseFileDescriptorLimit(int nMinFD);
|
|||
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
|
||||
bool RenameOver(fs::path src, fs::path dest);
|
||||
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
|
||||
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
||||
bool DirIsWritable(const fs::path& directory);
|
||||
|
||||
/** Release all directory locks. This is used for unit testing only, at runtime
|
||||
|
|
|
@ -126,11 +126,18 @@ void BerkeleyEnvironment::Close()
|
|||
}
|
||||
}
|
||||
|
||||
FILE* error_file = nullptr;
|
||||
dbenv->get_errfile(&error_file);
|
||||
|
||||
int ret = dbenv->close(0);
|
||||
if (ret != 0)
|
||||
LogPrintf("BerkeleyEnvironment::Close: Error %d closing database environment: %s\n", ret, DbEnv::strerror(ret));
|
||||
if (!fMockDb)
|
||||
DbEnv((u_int32_t)0).remove(strPath.c_str(), 0);
|
||||
|
||||
if (error_file) fclose(error_file);
|
||||
|
||||
UnlockDirectory(strPath, ".walletlock");
|
||||
}
|
||||
|
||||
void BerkeleyEnvironment::Reset()
|
||||
|
|
|
@ -315,6 +315,14 @@ class MultiWalletTest(BitcoinTestFramework):
|
|||
self.nodes[0].loadwallet(wallet_name)
|
||||
assert_equal(rpc.getaddressinfo(addr)['ismine'], True)
|
||||
|
||||
# Test .walletlock file is closed
|
||||
self.start_node(1)
|
||||
wallet = os.path.join(self.options.tmpdir, 'my_wallet')
|
||||
self.nodes[0].createwallet(wallet)
|
||||
assert_raises_rpc_error(-4, "Error initializing wallet database environment", self.nodes[1].loadwallet, wallet)
|
||||
self.nodes[0].unloadwallet(wallet)
|
||||
self.nodes[1].loadwallet(wallet)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
MultiWalletTest().main()
|
||||
|
|
Loading…
Reference in a new issue