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

cli: create new tracing span in mt-start-sql #113553

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

yuzefovich
Copy link
Member

This commit fixes a possible misuse of the tracing infrastructure with mt start-sql command. In particular, previously it was possible for a tracing span created (and finished) in runStartInternal to be used by a couple of things in makeTenantSQLServerArgs (main one being rpc.Context) that hold on to the context after the corresponding span has been finished. This is disallowed (since we reuse spans after Finish has been called on them) and was recently discovered. This problem is now fixed by deriving a child span only in mt start-sql code path that is never finished (since those users can be active throughout the whole lifetime of the tenant server).

The bug is pretty minor (I think only serverless is affected), so there is no release note.

Fixes: #113170.

Release note: None

@yuzefovich yuzefovich requested review from stevendanna and a team November 1, 2023 02:13
@yuzefovich yuzefovich requested review from a team as code owners November 1, 2023 02:13
Copy link

blathers-crl bot commented Nov 1, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@yuzefovich yuzefovich added the backport-23.2.x Flags PRs that need to be backported to 23.2. label Nov 1, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Thanks for tracking this down.

An alternative would be to make NewSeparateProcessTenantServer closer to NewServer -- which doesn't take a context and builds its own from context.Background().

But I think what you have here makes sense. The context we are deriving from is cancelled eventually, but only as a defer in runStartInternal which should only happen after we've already returned from waitForShutdown() -- which is probably closer to what we want.

Overall, I think the context management in the server startup is rather unclear. In addition to the cases you called out in the original issue, if you read through the various startup paths, we capture contexts in various closures in multiple places, all of which seem a bit suspect to me. But, that is a task for a different day.

This commit fixes a possible misuse of the tracing infrastructure with
`mt start-sql` command. In particular, previously it was possible for
a tracing span created (and finished) in `runStartInternal` to be used
by a couple of things in `makeTenantSQLServerArgs` (main one being
`rpc.Context`) that hold on to the context after the corresponding span
has been finished. This is disallowed (since we reuse spans after
`Finish` has been called on them) and was recently discovered. This
problem is now fixed by deriving a child span only in `mt start-sql`
code path that is never finished (since those users can be active
throughout the whole lifetime of the tenant server).

The bug is pretty minor (I think only serverless is affected), so there
is no release note.

Release note: None
@yuzefovich
Copy link
Member Author

I agree with your reasoning, so I added a TODO to explore the refactoring at some point. For now this seems good enough.

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Nov 1, 2023

Build succeeded:

@craig craig bot merged commit 63e0b12 into cockroachdb:master Nov 1, 2023
3 checks passed
Copy link

blathers-crl bot commented Nov 1, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error setting reviewers, but backport branch blathers/backport-release-23.2-113553 is ready: POST https://api.github.com/repos/cockroachdb/cockroach/pulls/113595/requested_reviewers: 422 Reviews may only be requested from collaborators. One or more of the teams you specified is not a collaborator of the cockroachdb/cockroach repository. []

Backport to branch 23.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@yuzefovich yuzefovich deleted the fix-mt-span branch November 1, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.2.x Flags PRs that need to be backported to 23.2.
Projects
None yet
3 participants