Skip to content

Commit 783fbaf

Browse files
committed
Bugfix: RPC: Attempt to delete cookie tmp before creating it
May be needed if we ended up with a read-only tmp file
1 parent 051c276 commit 783fbaf

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/rpc/request.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie
112112
if (filepath_tmp.empty()) {
113113
return true; // -norpccookiefile
114114
}
115+
try {
116+
fs::remove(filepath_tmp);
117+
} catch (const fs::filesystem_error& e) {
118+
// ignore
119+
}
115120
file.open(filepath_tmp);
116121
if (!file.is_open()) {
117122
LogWarning("Unable to open cookie authentication file %s for writing", fs::PathToString(filepath_tmp));

test/functional/rpc_users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ def run_test(self):
200200
cookie_path = self.nodes[0].chain_path / ".cookie"
201201
cookie_path_tmp = self.nodes[0].chain_path / ".cookie.tmp"
202202
cookie_path_tmp.mkdir()
203+
cookie_path_tmp_subdir = cookie_path_tmp / "subdir"
204+
cookie_path_tmp_subdir.mkdir()
203205
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
206+
cookie_path_tmp_subdir.rmdir()
204207
cookie_path_tmp.rmdir()
205208
assert not cookie_path.exists()
206209
self.restart_node(0)

0 commit comments

Comments
 (0)