-
Notifications
You must be signed in to change notification settings - Fork 27
RSDK-6158 - initial connection options #376
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
RSDK-6158 - initial connection options #376
Conversation
src/viam/sdk/rpc/dial.cpp
Outdated
| } | ||
|
|
||
| void DialOptions::set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout) { | ||
| initial_connection_attempt_timeout_ = std::move(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.
minor but you can remove the std::move here, a chrono::duration<T> is a T under the hood, no need to std::move a float.
I am seeing that this was also how it was done in set_timeout above, so maybe that can be a drive-by
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.
I wonder if clang-tidy will think of it as a missed move? Personally, I always move things like these, since otherwise it feels like I'm making assumptions about implementation.
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.
I generally err on the side of move unless clang explicitly tells me not to do so just because it's simpler and makes me less likely to miss a move that is relevant but I don't feel particularly strongly. I'm happy to go with whatever makes sense to y'all!
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.
Ended up going with @lia-viam's suggestion just because it was the one that came in first. But again, I'm not picky and my slight inclination if anything is to keep moveing things even if it's unnecessary. So if you two land on the other approach I'm happy to change it back.
src/viam/sdk/rpc/dial.hpp
Outdated
| bool allows_insecure_downgrade() const; | ||
| const std::chrono::duration<float>& timeout() const; | ||
| int initial_connection_attempts() const; | ||
| const std::chrono::duration<float>& initial_connection_attempt_timeout() const; |
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.
Let's return this by value instead of ref to const; see other comment
src/viam/sdk/rpc/dial.cpp
Outdated
| auto connection = dial(uri, opts); | ||
| opts.set_timeout(timeout); | ||
| return connection; | ||
| } catch (...) { |
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.
Let's just catch const std::exception& here, a catch (...) is generally inadvisable except at application boundaries.
src/viam/sdk/rpc/dial.cpp
Outdated
| const boost::optional<DialOptions>& options, | ||
| bool initial_attempt) { | ||
| if (!initial_attempt) { | ||
| return dial(std::move(uri), options); |
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.
| return dial(std::move(uri), options); | |
| return dial(uri, options); |
acmorrow
left a comment
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.
Just taking a look, random thoughts, feel free to do with them as you see fit.
src/viam/sdk/rpc/dial.hpp
Outdated
| void set_credentials(boost::optional<Credentials> creds); | ||
| void set_allow_insecure_downgrade(bool allow); | ||
| void set_timeout(std::chrono::duration<float> timeout); | ||
| void set_initial_connection_attempts(int attempts); |
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.
A small proposal: these and the other set_x methods should return DialOptions& so you can chain them:
DialOptions options{};
options.set_entity(...).set_timeout(...)....;
src/viam/sdk/rpc/dial.hpp
Outdated
|
|
||
| // allows for specifying that this dial is an initial connection attempt, indicating that | ||
| // initial connection options should be used. | ||
| static std::shared_ptr<ViamChannel> dial(const char* uri, |
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.
I have something of a personal dislike for bool parameters like this, and it makes me wonder why this initial aspect isn't either just a setting on the DialOptions, or a differently named method.
My distaste arrises because at the call site, you end up like this:
ViamChannel::dial(my_uri, my_options, false);
What does false mean?
Whereas either of these makes the intention clear at the call site without needing to chase down the declaration / documentation for dial:
ViamChannel::dial(my_uri, my_options.as_initial());
or
ViamChannel::dial_initial(my_uri, my_options)
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.
I like the look of the as_initial approach but I think it requires creating a copy of the options. So, went with dial_initial.
src/viam/sdk/rpc/dial.cpp
Outdated
| } | ||
|
|
||
| void DialOptions::set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout) { | ||
| initial_connection_attempt_timeout_ = std::move(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.
I wonder if clang-tidy will think of it as a missed move? Personally, I always move things like these, since otherwise it feels like I'm making assumptions about implementation.
src/viam/sdk/rpc/dial.cpp
Outdated
| } | ||
| } | ||
|
|
||
| throw Exception(ErrorCondition::k_connection, "Unable to establish connection"); |
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.
Should this maybe instead throw whatever the last exception was, so that the information about the cause of the failure isn't lost?
src/viam/sdk/rpc/dial.hpp
Outdated
| static std::shared_ptr<ViamChannel> dial(const char* uri, | ||
| const boost::optional<DialOptions>& options); | ||
|
|
||
| // Specifies that this dial is an initial connection attempt and that initial connection options |
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 seems as good a time as any to doc comment this function, as well as dial above.
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.
Done; added a clause as well clarifying that use of dial is discouraged and that RobotClient::at_address(...) is preferred.
src/viam/sdk/rpc/dial.cpp
Outdated
| return connection; | ||
| } catch (const std::exception& e) { | ||
| attempts_remaining -= 1; | ||
| exception = e; |
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 is going to slice the exception, I think (i.e. only the std::exception part will be copied, but any subtype will be lost). I think you can just look at attempts_remaining inside the catch and throw if there are non left.
acmorrow
left a comment
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.
LGTM
No description provided.