newrelic / newrelic-dotnet-agent

The New Relic .NET language agent.
Apache License 2.0
96 stars 57 forks source link

Verify correct Dispose() behavior during application shutdown #2795

Open tippmar-nr opened 10 hours ago

tippmar-nr commented 10 hours ago

Describe the story, please be clear on scope of the story.

We have seen reports of an occasional deadlock during application shutdown that could be related to the Dispose() implementation in some of our services. The symptom is that the logs indicate that the agent is shutting down, but the application continues to process one or more timers, sending data to the collector and logging about it. Our analysis indicates that this could only happen if the Dispose() call in AgentManager.Shutdown() somehow didn't finish -- if it were to finish, the Serilog logger would have been closed and no further log messages could have been emitted.

There are a few implementations of Dispose() that seem a little bit suspect -- in particular, any Dispose() method that calls base.Dispose() before doing its own work should be analyzed for correctness. In general, the correct pattern is for a derived class to clean up its resources prior to calling the base class Dispose() method.

One location we've been able to identify in crash dumps is GCSamplerNetCore.Dispose() - as well as the base class hierarchy from that class. There are, no doubt, others that should be investigated as well.

Acceptance Criteria

The .NET agent should successfully shutdown and dispose all services without deadlocks

Estimates

Please provide initial t-shirt size M

workato-integration[bot] commented 10 hours ago

https://new-relic.atlassian.net/browse/NR-321943