Skip to content

Commit 727175a

Browse files
author
MarcoFalke
committed
Merge bitcoin#12902: [qa] Handle potential cookie race when starting node
75d0e4c [qa] Delete cookie file before starting node (Suhas Daftuar) Pull request description: When a node is restarted during a test after an unclean shutdown (such as with -dbcrashratio), it's possible an old cookie file was left behind. This can cause a race condition when restarting the node, where the test framework might try to connect using credentials from the old cookie file, just as the node will generate new credentials and overwrite the old file. Delete any such cookie file if present prior to startup. Tree-SHA512: ae1e8bf8fd20e07c32b0715025693bb28b0e3dd34f328cae4346abf579b0c97b5db1c02782e1c46b7a3b6058d268b6d46b668e847658a6eed0be857ffb0d65dc
2 parents 06ead15 + 75d0e4c commit 727175a

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,
@@ -116,6 +117,10 @@ def start(self, extra_args=None, stderr=None, *args, **kwargs):
116117
extra_args = self.extra_args
117118
if stderr is None:
118119
stderr = self.stderr
120+
# Delete any existing cookie file -- if such a file exists (eg due to
121+
# unclean shutdown), it will get overwritten anyway by bitcoind, and
122+
# potentially interfere with our attempt to authenticate
123+
delete_cookie_file(self.datadir)
119124
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs)
120125
self.running = True
121126
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)