Skip to content

Commit 75d0e4c

Browse files
committed
[qa] Delete cookie file before starting node
If a cookie file exists in a datadir prior to node startup, it must have been leftover from a prior unclean shutdown. As bitcoind will overwrite it anyway, delete it before starting up to prevent the test framework from inadvertently trying to connect using stale credentials.
1 parent 2b54155 commit 75d0e4c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

test/functional/test_framework/test_node.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .util import (
2121
append_config,
2222
assert_equal,
23+
delete_cookie_file,
2324
get_rpc_proxy,
2425
rpc_url,
2526
wait_until,
@@ -105,6 +106,10 @@ def start(self, extra_args=None, stderr=None, *args, **kwargs):
105106
extra_args = self.extra_args
106107
if stderr is None:
107108
stderr = self.stderr
109+
# Delete any existing cookie file -- if such a file exists (eg due to
110+
# unclean shutdown), it will get overwritten anyway by bitcoind, and
111+
# potentially interfere with our attempt to authenticate
112+
delete_cookie_file(self.datadir)
108113
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs)
109114
self.running = True
110115
self.log.debug("bitcoind started, waiting for RPC to come up")

test/functional/test_framework/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ def get_auth_cookie(datadir):
332332
raise ValueError("No RPC credentials")
333333
return user, password
334334

335+
# If a cookie file exists in the given datadir, delete it.
336+
def delete_cookie_file(datadir):
337+
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
338+
logger.debug("Deleting leftover cookie file")
339+
os.remove(os.path.join(datadir, "regtest", ".cookie"))
340+
335341
def get_bip9_status(node, key):
336342
info = node.getblockchaininfo()
337343
return info['bip9_softforks'][key]

0 commit comments

Comments
 (0)