Skip to content

client: addrConn NewStream and health check cleanup#2848

Merged
menghanl merged 8 commits intogrpc:masterfrom
menghanl:ac_stream_and_health_check
Jun 26, 2019
Merged

client: addrConn NewStream and health check cleanup#2848
menghanl merged 8 commits intogrpc:masterfrom
menghanl:ac_stream_and_health_check

Conversation

@menghanl
Copy link
Contributor

  1. Make newStream() take string (for method) so it can be used for out-of-band load reporting (which will also be a stream on an addrConn)
  2. move healthcheck (streaming) related functions into a function
  3. make ac.newClientStream not a method of addrConn
    • so it's (should be) easier to merge with cc.newStream()

}
}
c.maxReceiveMessageSize = getMaxSize(nil, c.maxReceiveMessageSize, defaultClientMaxReceiveMessageSize)
c.maxSendMessageSize = getMaxSize(nil, c.maxSendMessageSize, defaultServerMaxSendMessageSize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the position of this block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more similar to clientConn.NewStream().

if ac.transport != currentTr {
return nil, status.Error(codes.Canceled, "the provided transport is no longer valid to use")
}
return newNonRetryClientStream(ctx, &StreamDesc{ServerStreams: true}, method, currentTr, ac)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newNonRetryClientStream holds the ac.mu lock the whole time. Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlocked.

return nil, status.Error(codes.Canceled, "the provided transport is no longer valid to use")
}
// transition to CONNECTING state when an attempt starts
if ac.state != connectivity.Connecting {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleting this state transition will lead to invalid state transition such as IDLE -> READY, TRANSIENT FAILURE -> READY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing connectivity state when creating a stream on the addrConn in general doesn't sound right.
Also, this is to create a general purpose stream on the addrConn (as opposite to a health checking stream), so changing connectivity state is just not going to work.

TransientFailure<->Ready is already happening today with the health check stream.

This function is called only when connection is created, so the state is not IDLE.

Copy link
Contributor Author

@menghanl menghanl Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransientFailure<->Ready is already happening today with the health check stream.

This is not true, because newStream() will set ac's state to connecting.
The fix is to manually set state to connecting before calling newStream(), in the health checking goroutine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the "invalid" transition still happens when the health checking stream is good, but server reports unhealthy. But we still need the manual transition to connecting when stream is broken (this behavior is defined in the spec).

@menghanl menghanl force-pushed the ac_stream_and_health_check branch from 9f7e49f to e511624 Compare June 18, 2019 23:23
@dfawley dfawley assigned lyuxuan and unassigned lyuxuan Jun 20, 2019
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the cleanups. Just a couple very small things to consider.

defer func() { backoffFunc = oldBackoffFunc }()

clientHealthCheck(context.Background(), newStream, func(_ bool) {}, "test")
clientHealthCheck(context.Background(), newStream, func(_ connectivity.State) {}, "test")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "_" here is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Why doesn't gofmt fix this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you haven't made it do that yet! 😁

//
// The health checking protocol is defined at:
// https://github.com/grpc/grpc/blob/master/doc/health-checking.md
type HealthChecker func(ctx context.Context, newStream func(string) (interface{}, error), reportHealth func(connectivity.State), serviceName string) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should reportHealth be renamed to setSubchannelState or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@menghanl menghanl force-pushed the ac_stream_and_health_check branch from e511624 to d1a2f44 Compare June 21, 2019 20:29
@dfawley dfawley removed their assignment Jun 21, 2019
@menghanl menghanl merged commit 5caf962 into grpc:master Jun 26, 2019
@menghanl menghanl deleted the ac_stream_and_health_check branch June 26, 2019 18:15
@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants