-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow timeouts in the client methods that make API call #3964
Conversation
Important Auto Review SkippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
// NB(forrest): since `GetAllVersions` is an API call - in the event the server is un-reachable | ||
// we timeout after 3 seconds to avoid waiting on an unavailable server to return its version information. | ||
vctx, cancel := context.WithTimeout(ctx, time.Second*3) | ||
defer cancel() | ||
var err error | ||
versions, err = util.GetAllVersions(ctx) | ||
versions, err = util.GetAllVersions(vctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change will cause the bacalhau version
command to return quickly if the server (requester) is unreachable.
Authenticate: func(ctx context.Context, a *clientv2.Auth) (*apimodels.HTTPCredential, error) { | ||
return auth.RunAuthenticationFlow(ctx, cmd, a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change allows calls to the authentication API to respect context cancellation in the event the server (requester) serving the /api/v1/auth
endpoint is unreachable. Previously we used the less explicit command context for this method
// NB(forrest): since `GetAllVersions` is an API call - in the event the server is un-reachable | ||
// we timeout after 3 seconds to avoid waiting on an unavailable server to return its version information. | ||
vctx, cancel := context.WithTimeout(ctx, time.Second*3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do we log or return to the user after the 3 seconds timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only return the client version in that case:
> export BACALHAU_API_HOST=1.1.1.1
> bacalhau version
CLIENT UPDATE MESSAGE
v1.3.0-43-g9debb92e9
> export BACALHAU_API_HOST=bootstrap.production.bacalhau.org
> bacalhau version
CLIENT SERVER LATEST UPDATE MESSAGE
v1.3.0-43-g9debb92e9 v1.3.0 v1.3.0
The log message below this comment on line 112 isn't returned to the user on the CLI since we only log Fatal
for CLI calls.
9debb92
to
38b82d7
Compare
38b82d7
to
e2da450
Compare
Allows
bacalhau version
to fail quickly if the server is offline.