Skip to content
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

Throttler: set timeouts on gRPC communication and on topo communication #14165

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions go/vt/vttablet/tabletserver/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ func (throttler *Throttler) Operate(ctx context.Context) {

func (throttler *Throttler) generateTabletHTTPProbeFunction(ctx context.Context, tmClient tmclient.TabletManagerClient, clusterName string, probe *mysql.Probe) (probeFunc func() *mysql.MySQLThrottleMetric) {
return func() *mysql.MySQLThrottleMetric {
// Some reasonable timeout, to ensure we release connections even if they're hanging (otherwise grpc-go keeps polling those connections forever)
ctx, cancel := context.WithTimeout(ctx, 4*mysqlCollectInterval)
Copy link
Member

@deepthi deepthi Oct 3, 2023

Choose a reason for hiding this comment

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

Now that I look at this again, this local variable hides the context that is being passed in. If you are passed in a long-lived context and you want to use a shorter one within the function, it should be named something else.
Which also brings up the question - what is being passed in here? Is it context.Background()? that is bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, didn't notice this comment before merging.

The context being passed is not context.Backgound(). It is the context sent to Operate(). And this is also the reason why disable&enable the throttler fixes the issue: Disable() cancels the context, which runs all the way down to cancelling the connection!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hiding the original context is fine -- the only consumer of the context is the gRPC call.

defer cancel()

// Hit a tablet's `check-self` via HTTP, and convert its CheckResult JSON output into a MySQLThrottleMetric
mySQLThrottleMetric := mysql.NewMySQLThrottleMetric()
mySQLThrottleMetric.ClusterName = clusterName
Expand Down Expand Up @@ -872,6 +876,9 @@ func (throttler *Throttler) refreshMySQLInventory(ctx context.Context) error {
}
// The primary tablet is also in charge of collecting the shard's metrics
err := func() error {
ctx, cancel := context.WithTimeout(ctx, mysqlRefreshInterval)
defer cancel()

tabletAliases, err := throttler.ts.FindAllTabletAliasesInShard(ctx, throttler.keyspace, throttler.shard)
if err != nil {
return err
Expand Down
Loading