Skip to content

Commit

Permalink
Merge #22327: cli: Avoid truncating -rpcwaittimeout
Browse files Browse the repository at this point in the history
fa34cb8 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:
    ACK fa34cb8 review, debug-built, tested
  theStack:
    Tested ACK fa34cb8

Tree-SHA512: 7158da8545f9998a82bcc8636e04564efdb1e1be43b4288298c151b4df29ad47a2760259eefadd4a01db92ea18a1e017f3febc1cd8c69a4b28c86180229d8c90
  • Loading branch information
MarcoFalke committed Jun 24, 2021
2 parents 0553d75 + fa34cb8 commit b2f5c38
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()));
}
Expand Down

0 comments on commit b2f5c38

Please sign in to comment.