Skip to content

Commit 7460945

Browse files
sdaftuarMarcoFalke
authored andcommitted
[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. Github-Pull: #12902 Rebased-From: 75d0e4c
1 parent 0a76ed2 commit 7460945

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
@@ -17,6 +17,7 @@
1717
from .authproxy import JSONRPCException
1818
from .util import (
1919
assert_equal,
20+
delete_cookie_file,
2021
get_rpc_proxy,
2122
rpc_url,
2223
wait_until,
@@ -98,6 +99,10 @@ def start(self, extra_args=None, stderr=None, *args, **kwargs):
9899
extra_args = self.extra_args
99100
if stderr is None:
100101
stderr = self.stderr
102+
# Delete any existing cookie file -- if such a file exists (eg due to
103+
# unclean shutdown), it will get overwritten anyway by bitcoind, and
104+
# potentially interfere with our attempt to authenticate
105+
delete_cookie_file(self.datadir)
101106
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs)
102107
self.running = True
103108
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
@@ -319,6 +319,12 @@ def get_auth_cookie(datadir):
319319
raise ValueError("No RPC credentials")
320320
return user, password
321321

322+
# If a cookie file exists in the given datadir, delete it.
323+
def delete_cookie_file(datadir):
324+
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
325+
logger.debug("Deleting leftover cookie file")
326+
os.remove(os.path.join(datadir, "regtest", ".cookie"))
327+
322328
def get_bip9_status(node, key):
323329
info = node.getblockchaininfo()
324330
return info['bip9_softforks'][key]

0 commit comments

Comments
 (0)