aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-04-09 19:11:07 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-04-09 19:11:08 -0400
commit727175a08dffcb5f18f8faac562ab54f89e5f36e (patch)
tree877d084a3fd9cd2d6c3a67bbf0309bb6a701bcd4
parent06ead15050f54d10125a72afe1c6c47150f6a73c (diff)
parent75d0e4c5444249f0cf81ed0494e2c2717170b695 (diff)
Merge #12902: [qa] Handle potential cookie race when starting node
75d0e4c544 [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
-rwxr-xr-xtest/functional/test_framework/test_node.py5
-rw-r--r--test/functional/test_framework/util.py6
2 files changed, 11 insertions, 0 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 966b0463c2..0f0d031f35 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -20,6 +20,7 @@ from .authproxy import JSONRPCException
from .util import (
append_config,
assert_equal,
+ delete_cookie_file,
get_rpc_proxy,
rpc_url,
wait_until,
@@ -116,6 +117,10 @@ class TestNode():
extra_args = self.extra_args
if stderr is None:
stderr = self.stderr
+ # Delete any existing cookie file -- if such a file exists (eg due to
+ # unclean shutdown), it will get overwritten anyway by bitcoind, and
+ # potentially interfere with our attempt to authenticate
+ delete_cookie_file(self.datadir)
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs)
self.running = True
self.log.debug("bitcoind started, waiting for RPC to come up")
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index a24a2ec4f5..f22322fbbc 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -332,6 +332,12 @@ def get_auth_cookie(datadir):
raise ValueError("No RPC credentials")
return user, password
+# If a cookie file exists in the given datadir, delete it.
+def delete_cookie_file(datadir):
+ if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
+ logger.debug("Deleting leftover cookie file")
+ os.remove(os.path.join(datadir, "regtest", ".cookie"))
+
def get_bip9_status(node, key):
info = node.getblockchaininfo()
return info['bip9_softforks'][key]