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

tracing: fix corruption of structured recording buffer #75099

Merged
merged 1 commit into from
Jan 20, 2022

Conversation

andreimatei
Copy link
Contributor

This patch fixes a bug leading to corruption of one of the Span's
recording buffers.
We had broken code like the following:

for _, e := range c.StructuredRecords {
        s.recordInternalLocked(&e, &s.mu.recording.structured)
}

recordInternalLocked(ptr) takes ownership of ptr, so the &e is
broken because e keep being reassigned.

The bug was causing buffer elements to essentially be overwritten. In
turn, this was leading to inconsistencies in the accounting of the size
of the buffer's elements - we were maintaining a size sum that was
diverging from the overwritten reality.

Fixes #74994
Fixes #75045

Release note: None

@andreimatei andreimatei requested a review from a team January 18, 2022 20:53
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@abarganier abarganier left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

Copy link
Contributor

@irfansharif irfansharif left a comment

Choose a reason for hiding this comment

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

Any idea why #73876 made it worse/was bisected to?

for _, c := range children {
for _, e := range c.StructuredRecords {
s.recordInternalLocked(&e, &s.mu.recording.structured)
for c := range children {
Copy link
Contributor

Choose a reason for hiding this comment

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

[mega nit] c looks like it'd be of type tracingpb.RecordedSpan but it's an index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to ci

@andreimatei
Copy link
Contributor Author

Any idea why #73876 made it worse/was bisected to?

Not really. The symptoms that the failed tests report (trying to read the first element of an empty buffer) are caused by the fact that the computed size of the buffer is not kept in sync with reality, which is a problem when a span overflows its byte limit for the structured recordings. So one thing that would trigger it is a change that makes some span accumulate more structured recordings than before.

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @irfansharif)

Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @irfansharif)

This patch fixes a bug leading to corruption of one of the Span's
recording buffers.
We had broken code like the following:
```
for _, e := range c.StructuredRecords {
        s.recordInternalLocked(&e, &s.mu.recording.structured)
}
```
`recordInternalLocked(ptr)` takes ownership of ptr, so the `&e` is
broken because `e` keep being reassigned.

The bug was causing buffer elements to essentially be overwritten. In
turn, this was leading to inconsistencies in the accounting of the size
of the buffer's elements - we were maintaining a size sum that was
diverging from the overwritten reality.

Fixes cockroachdb#74994
Fixes cockroachdb#75045

Release note: None
@andreimatei andreimatei force-pushed the tracing.fix-structured-buf branch from fb7f04e to 5a1adf7 Compare January 19, 2022 22:47
@craig
Copy link
Contributor

craig bot commented Jan 19, 2022

Canceled.

@andreimatei
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 20, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 20, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 20, 2022

Build succeeded:

@craig craig bot merged commit 46bdd4e into cockroachdb:master Jan 20, 2022
@andreimatei andreimatei deleted the tracing.fix-structured-buf branch January 21, 2022 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants