Heap dumps: every SDK shutdown logs "Error waiting for GarbageCollectionMonitor task to complete"

オープン 初心者向け
#6,039 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@pcbeingused33 がすでに取り組んでいます。

2026年12月1日 から。

  • #6069 @pcbeingused33 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
backend

調査の方向性

src/Sentry/Internal/MemoryMonitor.csから始め、特に45~49行目付近の継続処理の設定と、176~191行目付近のシャットダウン処理を確認してください。破棄中に待機するタスクにキャンセルがどう影響するかを追い、その後、関連するメモリモニターのテストを調べてください。ヒープダンプを有効にした通常のシャットダウンでエラーがログに記録されなくなり、モニターの障害は引き続き報告される状態が完了の条件です。

索引モデルが issue の本文から書いたものです。

説明

State: Needs Discussion

With heap dumps enabled, every normal SDK shutdown logs this at Error level:

  Error: Error waiting for GarbageCollectionMonitor task to complete
System.AggregateException: One or more errors occurred. (A task was canceled.)
 ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Sentry.Internal.MemoryMonitor.Dispose()
   at Sentry.Internal.Hub.Dispose()
   at Sentry.Integrations.AppDomainProcessExitIntegration.HandleProcessExit(Object sender, EventArgs e)

Nothing is actually wrong. It's just noise, but it shows up for anyone with Debug on, and at Error level it looks like a real failure.

Cause

_monitorTask isn't the monitor task itself. It's the ContinueWith(..., TaskContinuationOptions.OnlyOnFaulted) continuation that logs monitor failures:

https://github.com/getsentry/sentry-dotnet/blob/5b87764710f537b594cd90a90bc0da34a40a22f6/src/Sentry/Internal/MemoryMonitor.cs#L45-L49

On shutdown, Dispose cancels the token, and the monitor stops without faulting. An OnlyOnFaulted continuation gets cancelled when its antecedent doesn't fault, so _monitorTask.Wait(500) throws an AggregateException that wraps a TaskCanceledException. The catch (OperationCanceledException) doesn't match the wrapper, so the general catch logs it as an error:

https://github.com/getsentry/sentry-dotnet/blob/5b87764710f537b594cd90a90bc0da34a40a22f6/src/Sentry/Internal/MemoryMonitor.cs#L176-L191

Repro

Console app on .NET 10, macOS arm64. Reproduces on 5.0.1 and on current main (7.1.0+):

SentrySdk.Init(o =>
{
    o.Dsn = "...";
    o.Debug = true;
    o.EnableHeapDumps((_, _) => false);
});
// let the app exit normally

The trigger doesn't need to fire. The error is logged whenever the SDK is disposed with heap dumps enabled.

Possible fix

Keep a reference to the monitor task itself and wait on that, or treat an AggregateException whose inner exceptions are all OperationCanceledException as a normal shutdown.

Found while reproducing #4007.

主要言語
C#
スター
775
フォーク
262
平均マージ
1日 16時間
マージ済み PR(30日)
118

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

getsentry/sentry-dotnet のほかの issue

getsentry/sentry-dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。