mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 22:42:04 +01:00
Merge bitcoin/bitcoin#22327: cli: Avoid truncating -rpcwaittimeout
fa34cb8024
cli: Avoid truncating -rpcwaittimeout (MarcoFalke) Pull request description: `seconds` is not enough precision to "exactly" store a timestamp n seconds into the future. Improve the precision by using `microseconds`. Fixes #22325 Also, use chrono literals. ACKs for top commit: jonatack: ACKfa34cb8024
review, debug-built, tested theStack: Tested ACKfa34cb8024
Tree-SHA512: 7158da8545f9998a82bcc8636e04564efdb1e1be43b4288298c151b4df29ad47a2760259eefadd4a01db92ea18a1e017f3febc1cd8c69a4b28c86180229d8c90
This commit is contained in:
commit
b2f5c38333
1 changed files with 3 additions and 3 deletions
|
@ -797,7 +797,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
|
|||
// Execute and handle connection failures with -rpcwait.
|
||||
const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
|
||||
const int timeout = gArgs.GetArg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT);
|
||||
const int64_t deadline = GetTime<std::chrono::seconds>().count() + timeout;
|
||||
const auto deadline{GetTime<std::chrono::microseconds>() + 1s * timeout};
|
||||
|
||||
do {
|
||||
try {
|
||||
|
@ -810,9 +810,9 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
|
|||
}
|
||||
break; // Connection succeeded, no need to retry.
|
||||
} catch (const CConnectionFailed& e) {
|
||||
const int64_t now = GetTime<std::chrono::seconds>().count();
|
||||
const auto now{GetTime<std::chrono::microseconds>()};
|
||||
if (fWait && (timeout <= 0 || now < deadline)) {
|
||||
UninterruptibleSleep(std::chrono::seconds{1});
|
||||
UninterruptibleSleep(1s);
|
||||
} else {
|
||||
throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what()));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue