Skip to content

Commit 2a04f8f

Browse files
jpnurmiclaude
andcommitted
fix: fall back SignalHandlerStrategy.ChainAtStart on incompatible .NET runtimes
Add a runtime version check that falls back to Default on .NET 10.0.0–10.0.3, which crash with ChainAtStart due to dotnet/runtime#123346. Also fix swapped runtime/SDK version numbers in XML docs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5a8dd6d commit 2a04f8f

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/Sentry/Platforms/Android/NativeOptions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ internal NativeOptions(SentryOptions options)
160160
/// The default value is <c>SignalHandlerStrategy.Default</c> (enabled).
161161
/// </summary>
162162
/// <remarks>
163-
/// When set to <see cref="Android.SignalHandlerStrategy.ChainAtStart"/>, .NET runtimes
164-
/// 10.0.100–10.0.301 shipped in .NET SDKs 10.0.0–10.0.3 will crash. The issue was fixed in
165-
/// <see href="https://github.com/dotnet/runtime/pull/123346">dotnet/runtime#123346</see>,
166-
/// which shipped as .NET runtime 10.0.400 in .NET SDK 10.0.4.
163+
/// .NET runtimes 10.0.0–10.0.3 (.NET SDKs 10.0.100–10.0.301) are not compatible with
164+
/// <see cref="Android.SignalHandlerStrategy.ChainAtStart"/>. On affected versions, the
165+
/// SDK automatically falls back to <see cref="Android.SignalHandlerStrategy.Default"/>.
166+
/// The issue was resolved in .NET runtime 10.0.4 (.NET SDK 10.0.400). See
167+
/// <see href="https://github.com/dotnet/runtime/pull/123346">dotnet/runtime#123346</see>.
167168
/// </remarks>
168169
public SignalHandlerStrategy SignalHandlerStrategy { get; set; } = SignalHandlerStrategy.Default;
169170

src/Sentry/Platforms/Android/SentrySdk.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ private static void InitSentryAndroidSdk(SentryOptions options)
6464
o.ServerName = options.ServerName;
6565
o.SessionTrackingIntervalMillis = (long)options.AutoSessionTrackingInterval.TotalMilliseconds;
6666
o.ShutdownTimeoutMillis = (long)options.ShutdownTimeout.TotalMilliseconds;
67-
o.SetNativeHandlerStrategy(options.Native.SignalHandlerStrategy switch
67+
var signalHandlerStrategy = options.Native.SignalHandlerStrategy;
68+
if (signalHandlerStrategy == SignalHandlerStrategy.ChainAtStart
69+
&& System.Environment.Version is { Major: 10, Minor: 0, Build: < 4 })
70+
{
71+
options.LogWarning(
72+
"SignalHandlerStrategy.ChainAtStart is not compatible with .NET runtime {0}. " +
73+
"Falling back to SignalHandlerStrategy.Default. Update to .NET runtime 10.0.4 or later.",
74+
System.Environment.Version);
75+
signalHandlerStrategy = SignalHandlerStrategy.Default;
76+
}
77+
o.SetNativeHandlerStrategy(signalHandlerStrategy switch
6878
{
6979
SignalHandlerStrategy.ChainAtStart => NdkHandlerStrategy.SentryHandlerStrategyChainAtStart,
7080
_ => NdkHandlerStrategy.SentryHandlerStrategyDefault

src/Sentry/Platforms/Android/SignalHandlerStrategy.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ public enum SignalHandlerStrategy
1616
/// signal handler.
1717
/// </summary>
1818
/// <remarks>
19-
/// .NET runtimes 10.0.100–10.0.301 shipped in .NET SDKs 10.0.0–10.0.3 crash when used
20-
/// with this option. The issue was fixed in
21-
/// <see href="https://github.com/dotnet/runtime/pull/123346">dotnet/runtime#123346</see>,
22-
/// which shipped as .NET runtime 10.0.400 in .NET SDK 10.0.4.
19+
/// .NET runtimes 10.0.0–10.0.3 (.NET SDKs 10.0.100–10.0.301) are not compatible with
20+
/// this strategy. On affected versions, the SDK automatically falls back to
21+
/// <see cref="Default"/>. The issue was resolved in .NET runtime 10.0.4
22+
/// (.NET SDK 10.0.400). See
23+
/// <see href="https://github.com/dotnet/runtime/pull/123346">dotnet/runtime#123346</see>.
2324
/// </remarks>
2425
ChainAtStart
2526
}

0 commit comments

Comments
 (0)