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
Improve connection handling #231
Conversation
lib/src/client/http2_connection.dart
Outdated
if (securityContext == null) { | ||
socket = await Socket.connect(host, port); | ||
} else { | ||
final socket = await SecureSocket.connect(host, port, |
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.
You're creating a new local variable here, so the outer socket
remains null. Perhaps name this secureSocket
, and then set socket = secureSocket
after the "h2" if check below?
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.
(also, is there any way to test this code path?)
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.
Oops
Thanks for catching this!
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 added a simple round trip test.
The interop tests would also have caught this. They run on master.
They should be set up to run on travis for pull requests. I have got some hints how to do this, but never got around to it :(.
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
socket.done.then((_) => _abandonConnection()); | ||
|
||
// Give the settings settings-frame a bit of time to arrive. | ||
await new Future.delayed(_estimatedRoundTripTime); |
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 like a smell - can we not be notified somehow when we're ready?
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 indeed a hack.
I don't think the http2 package currently exposes the possibility of waiting for the settings frame. Not sure we are even guaranteed to have one.
I'll add a TODO reminding us of the smell.
@mkustermann might have more insight.
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.
Maybe add a comment that explains why we do this, and how it could be better.
lib/src/client/http2_connection.dart
Outdated
final bool shouldRefresh = | ||
_connectionLifeTimer.elapsed > options.connectionTimeout; | ||
if (!isHealthy || shouldRefresh) { | ||
if (isHealthy) { |
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 the same as if (shouldRefresh)
, and there's no reason for it to be in the outer if
block.
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.
True - that reads simpler.
Thanks!
The old |
pubspec.yaml
Outdated
@@ -1,7 +1,7 @@ | |||
name: grpc | |||
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework. | |||
|
|||
version: 2.0.3 | |||
version: 2.0.4 |
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.
Considering the new options added to the public API, it might be fine to do a minor version bump.
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.
Right!
Done!
socket.done.then((_) => _abandonConnection()); | ||
|
||
// Give the settings settings-frame a bit of time to arrive. | ||
await new Future.delayed(_estimatedRoundTripTime); |
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.
Maybe add a comment that explains why we do this, and how it could be better.
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.
Thanks for the reviews!
socket.done.then((_) => _abandonConnection()); | ||
|
||
// Give the settings settings-frame a bit of time to arrive. | ||
await new Future.delayed(_estimatedRoundTripTime); |
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 indeed a hack.
I don't think the http2 package currently exposes the possibility of waiting for the settings frame. Not sure we are even guaranteed to have one.
I'll add a TODO reminding us of the smell.
@mkustermann might have more insight.
lib/src/client/http2_connection.dart
Outdated
final bool shouldRefresh = | ||
_connectionLifeTimer.elapsed > options.connectionTimeout; | ||
if (!isHealthy || shouldRefresh) { | ||
if (isHealthy) { |
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.
True - that reads simpler.
Thanks!
lib/src/client/http2_connection.dart
Outdated
if (securityContext == null) { | ||
socket = await Socket.connect(host, port); | ||
} else { | ||
final socket = await SecureSocket.connect(host, port, |
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 added a simple round trip test.
The interop tests would also have caught this. They run on master.
They should be set up to run on travis for pull requests. I have got some hints how to do this, but never got around to it :(.
pubspec.yaml
Outdated
@@ -1,7 +1,7 @@ | |||
name: grpc | |||
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework. | |||
|
|||
version: 2.0.3 | |||
version: 2.0.4 |
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.
Right!
Done!
Thanks @sigurdm - can you publish this to Pub too? |
Yep - done |
Most of this is appropriated from the grpc implementation we had in https://github.com/dart-lang/appengine. Big thanks to @mkustermann for exlpaining the intricate details!
This should make the connection handling a lot more robust, and also faster.
Hopefully dealing with: #228