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

Suspicious warning messages with tracing enabled (Trying to close a span that was already garbage collected) #1350

Closed
ZlobnyiSerg opened this issue Nov 25, 2021 · 11 comments
Assignees
Labels
Bug Something isn't working DiagnosticSource

Comments

@ZlobnyiSerg
Copy link

Environment

<PackageReference Include="Sentry" Version="3.11.1" />
<PackageReference Include="Sentry.AspNetCore" Version="3.11.1" />
<PackageReference Include="Sentry.Extensions.Logging" Version="3.11.1" />
.net 6

Steps to Reproduce

  1. Configure aspnet project to use Sentry tracing (app.UseSentryTracing())
  2. Create controller that creates EF DB context and queries something from DB
  3. Call this controller

Expected Result

No warnings in log file from Sentry

Actual Result

Lot of warning messages coming from Sentry:

[11:40:07 WRN] Trying to close a span that was already garbage collected. Connection
[11:40:07 WRN] Trying to close a span that was already garbage collected. QueryExecution
[11:40:07 WRN] Trying to close a span that was already garbage collected. QueryCompiler

I'm not sure if this is critical for functioning, but this makes noise in logs (with default configuration). I had to raise level for Sentry to Error.
If this is intended behaviour, please close this issue.

@ZlobnyiSerg ZlobnyiSerg changed the title Suspictious warning messages with tracing enabled (Trying to close a span that was already garbage collected) Suspicious warning messages with tracing enabled (Trying to close a span that was already garbage collected) Nov 25, 2021
@lucas-zimerman lucas-zimerman added Bug Something isn't working DiagnosticSource labels Nov 25, 2021
@bruno-garcia
Copy link
Member

Thanks for raising @ZlobnyiSerg
Those spans should have been closed before so something we need to look at.

@lucas-zimerman
Copy link
Collaborator

#1368 will resolve this problem.

@bruno-garcia
Copy link
Member

Should be fixed on 3.12.1.
Please reopen otherwise.

@ZlobnyiSerg
Copy link
Author

I've updated to 3.12.1, now we have less warnings but they're still there. For example:

[19:52:55 INF] Route matched with {action = "Update", controller = "Customers", page = ""}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Update(Int32, Model, System.Threading.CancellationToken) on controller Checkpoint.Web.Api.Controllers.CustomersController (Checkpoint.Web.Api).
[19:52:55 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:55 INF] Envelope '65dc851d09894611b90e90e9d2abef20' successfully received by Sentry.
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection
[19:52:56 WRN] Trying to close a span that was already garbage collected. Connection

@ZlobnyiSerg
Copy link
Author

@bruno-garcia I can't reopen this issue, maybe I have no rights?

@bruno-garcia bruno-garcia reopened this Dec 17, 2021
@lucas-zimerman
Copy link
Collaborator

We need to replace the logic that holds the spans references from here

private AsyncLocal<WeakReference<ISpan>> _spansCompilerLocal = new();
private AsyncLocal<WeakReference<ISpan>> _spansQueryLocal = new();
private AsyncLocal<WeakReference<ISpan>> _spansConnectionLocal = new();

One approach that could be followed is to do something similar to what was done on SqlListener
transaction?.StartChild(operation) is { } connectionSpan)

private static ISpan? TryGetQuerySpan(Scope scope, Guid operationId)
=> scope.Transaction?.Spans.FirstOrDefault(span => TryGetOperationId(span) == operationId);

Where we store the spans directly into the Scope transaction and locate them by the OperationId given by KeyValuePair<string, object?> value.

@mattjohnsonpint
Copy link
Contributor

@lucas-zimerman - Any update on this one?

@lucas-zimerman
Copy link
Collaborator

@lucas-zimerman - Any update on this one?

The warning noise was reduced on #1368.

As pointed on this comment #1350 (comment) the current code doesn't work correctly with multiple connections/queries on the same transaction, Ideally we could follow what was implemented on SentrySqlListener where the spans are located inside of the current active Transaction instead of an AsyncLocal WeakReference. But so far this change in the code wasn't developed

@WatchDogsDev
Copy link

When this noise will be cancelled ?

@jamescrosswell
Copy link
Collaborator

I'm pretty sure all of the above will be addressed in Fix/DB Connection spans presented poorly #2409. The Trying to close a span that was already garbage collected error was being surfaced because Sentry couldn't find the original spans that needed to be finished. Per the comment above we're no longer using AsyncLocal<WeakReference<ISpan>> to store a reference to the original spans and instead storing the correlation id that is supplied by diagnostics in the spans themselves.

I'll leave this issue open until the fix above is made available in the next release.

@jamescrosswell
Copy link
Collaborator

Closing this issues as it should be fixed with the 3.33.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working DiagnosticSource
Projects
Archived in project
Development

No branches or pull requests

7 participants