Skip to content

Commit

Permalink
common: Fix a potential cycle in the trace structure
Browse files Browse the repository at this point in the history
It turns out that under some circumstances we end up clearing the
pointee of `current` but not the pointer. Thus when we select the next
slot we can end up reusing the same slot, making it its own parent.

We forcefull break these cycles by enforcing that `current` should
never be returned and be set as its own parent.

Changelog-None
  • Loading branch information
cdecker committed Nov 22, 2024
1 parent f095f58 commit fe376f2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ static struct span *trace_span_slot(void)
* concurrent spans. */
assert(s);
assert(s->parent == NULL);

/* Be extra careful not to create cycles. If we return the
* position that is pointed at by current then we can only
* stub the trace by removing the parent link here. */
if (s == current)
current = NULL;

return s;
}

Expand Down

0 comments on commit fe376f2

Please sign in to comment.