qa: Prevent concurrency issues reading .cookie file
Summary:
Backport of core PR15771 (and PR14788).
This is expected to fix the TSAN errors like
https://build.bitcoinabc.org/viewLog.html?buildTypeId=BitcoinABC_ResourceIntensiveBuilds_BitcoinAbcMasterTsan&buildId=28539.
Test Plan: Run the CI TSAN build.
Reviewers: #bitcoin_abc, jasonbcox, markblundeberg
Reviewed By: #bitcoin_abc, jasonbcox, markblundeberg
Differential Revision: https://reviews.bitcoinabc.org/D5207