Skip to content

Fix shutdown of QueuedSpanCompleter#888

Merged
ybasket merged 1 commit intomasterfrom
fix-queued-span-completer-shutdown
Jul 19, 2023
Merged

Fix shutdown of QueuedSpanCompleter#888
ybasket merged 1 commit intomasterfrom
fix-queued-span-completer-shutdown

Conversation

@ybasket
Copy link
Copy Markdown
Contributor

@ybasket ybasket commented Jul 18, 2023

By having an uncancelable fiber via background and discarding the reference to it, the shut down wasn't awaiting the sending process to finish, causing spans to be lost. This bug probably got amplified in newer CE versions with improved performance, it manifested regularly in the Jaeger-based tests, see trace4cats/trace4cats-jaeger#175.

I tried adding a test case that would reproduce the issue, but failed as it seems to require real concurrency with thread switches that are hard to set up in a simple test case where as they come naturally from network I/O in integration tests.

By having an uncancelable fiber via background and discarding the reference to it, the shut down wasn't awaiting the sending process to finish, causing spans to be lost. This bug probably got amplified in newer CE versions with improved performance, it manifested regularly in the Jaeger-based tests, see trace4cats/trace4cats-jaeger#175.

I tried adding a test case that would reproduce the issue, but failed as it seems to require real concurrency with thread switches that are hard to set up in a simple test case where as they come naturally from network I/O in integration tests.
@ybasket ybasket requested a review from janstenpickle July 18, 2023 08:58
override def complete(span: CompletedSpan.Builder): F[Unit] =
channel
.trySend(span.build(process))
.flatMap(errorQueue.tryOffer(_).start.void)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not strictly needed to fix the issue, but as tryOffer is guaranteed to never semantically block, I don't see why we couldn't save ourselves from the overhead of starting a fiber on this relatively hot path.

@ybasket ybasket merged commit bc80c2f into master Jul 19, 2023
@mergify mergify bot deleted the fix-queued-span-completer-shutdown branch July 19, 2023 09:58
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