Skip to content

Commit

Permalink
Fix update token interval calculation. (ydb-platform#3064)
Browse files Browse the repository at this point in the history
We should chouse min value from expiresIn and RefreshPeriod_, not max one
Also reduce server returned interval by 2 to prevent race at expiring time.
  • Loading branch information
dcherednik authored Mar 22, 2024
1 parent a79b382 commit 431b71b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ydb/public/sdk/cpp/client/iam/common/iam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ class TIAMCredentialsProvider : public ICredentialsProvider {
if (auto it = respMap.find("expires_in"); it == respMap.end())
ythrow yexception() << "Result doesn't contain expires_in";
else {
const TDuration expiresIn = TDuration::Seconds(it->second.GetUInteger());
const TDuration expiresIn = TDuration::Seconds(it->second.GetUInteger()) / 2;

NextTicketUpdate_ = TInstant::Now() + std::max(expiresIn, RefreshPeriod_);
const auto interval = std::max(std::min(expiresIn, RefreshPeriod_), TDuration::MilliSeconds(100));

NextTicketUpdate_ = TInstant::Now() + interval;
}
} catch (...) {
}
Expand All @@ -83,4 +85,4 @@ TCredentialsProviderFactoryPtr CreateIamCredentialsProviderFactory(const TIamHos
return std::make_shared<TIamCredentialsProviderFactory>(params);
}

}
}

0 comments on commit 431b71b

Please sign in to comment.