Skip to content

Fix stale goroutine label#1453

Closed
brancz wants to merge 1 commit into
open-telemetry:mainfrom
parca-dev:go-label-name-fix
Closed

Fix stale goroutine label#1453
brancz wants to merge 1 commit into
open-telemetry:mainfrom
parca-dev:go-label-name-fix

Conversation

@brancz
Copy link
Copy Markdown
Contributor

@brancz brancz commented May 22, 2026

Previously it was possible that if a label was shorter than a previous one on the same CPU, that we didn't clear the remaining bytes, causing incorrect labels to be reported.

@florianl @christos68k

Previously it was possible that if a label was shorter than a previous
one on the same CPU, that we didn't clear the remaining bytes, causing
incorrect labels to be reported.
@brancz brancz requested review from a team as code owners May 22, 2026 10:25
@gnurizen
Copy link
Copy Markdown
Contributor

For the record this broke when we removed the zeroing here: 40dd9d9

// otherwise inherit the old trailing bytes. Userspace reconstructs the
// string by scanning for the first NUL, so leftover bytes would corrupt
// the label keys and values we emit.
__builtin_memset(lbl, 0, sizeof(*lbl));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

memset unrolls to 64 1 byte writes, not the end of the world but instead I think we should just write a null terminator since we don't store the length and the Go side treats it as a C-string. This is why we read at most LEN-1.

Comment thread tracer/tracer.go
trace := t.tracePool.Get().(*libpf.EbpfTrace)
// comm is best-effort: if the kernel handed us non-UTF-8 bytes, drop it
// rather than emit an invalid string downstream.
comm, _ := goString(ptr.Comm[:])
Copy link
Copy Markdown
Contributor

@gnurizen gnurizen May 22, 2026

Choose a reason for hiding this comment

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

Doing utf8 validation on comm feels wrong (like wasted energy) but its probably not a big deal.

Comment thread tracer/tracer.go
return libpf.Intern(pfunsafe.ToString(cstr[:index]))
b := cstr[:index]
if !utf8.Valid(b) {
return libpf.NullString, false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This throws away all the valid bits of the string in the case of a mid-rune truncation, feels like a bad idea, wouldn't it be better to skip the utf8 validation and let downstream consumers deal with it?

@brancz
Copy link
Copy Markdown
Contributor Author

brancz commented May 22, 2026

Closing to have @gnurizen take this over the finish line.

@gnurizen
Copy link
Copy Markdown
Contributor

super ceded by #1454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants