diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bd13841cd..f40c5c9d44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ > make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first. +## Unreleased + +### Fixes + +- Honor `shutdownTimeout` on iOS ([#6749](https://github.com/getsentry/sentry-react-native/pull/6749)) + ## 8.27.0 > [!WARNING] diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartTests.swift b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartTests.swift index 0bcd75dac7..431bc62123 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartTests.swift +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartTests.swift @@ -245,6 +245,27 @@ final class RNSentryStartTests: XCTestCase { XCTAssertFalse(actualOptions.enableMemoryIntrospection) } + func testShutdownTimeoutMapsMillisecondsToSeconds() throws { + try startFromRN(options: [ + "dsn": "https://abcd@efgh.ingest.sentry.io/123456", + // JS passes milliseconds; Cocoa's shutdownTimeInterval is in seconds + "shutdownTimeout": 5_000 + ]) + + let actualOptions = SentrySDK.internal.options + XCTAssertEqual(actualOptions.shutdownTimeInterval, 5.0) + } + + func testShutdownTimeoutDefault() throws { + try startFromRN(options: [ + "dsn": "https://abcd@efgh.ingest.sentry.io/123456" + ]) + + let actualOptions = SentrySDK.internal.options + // Cocoa's default shutdownTimeInterval is 2 seconds + XCTAssertEqual(actualOptions.shutdownTimeInterval, 2.0) + } + func startFromRN(options: [String: Any]) throws { var error: NSError? RNSentryStart.start(options: options, error: &error) diff --git a/packages/core/ios/RNSentryStart.m b/packages/core/ios/RNSentryStart.m index 2a499a995d..13c1230cab 100644 --- a/packages/core/ios/RNSentryStart.m +++ b/packages/core/ios/RNSentryStart.m @@ -197,6 +197,15 @@ + (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull) } } + // JS `shutdownTimeout` is in milliseconds (matching Android's `setShutdownTimeoutMillis`), + // while Cocoa's `shutdownTimeInterval` is an NSTimeInterval in seconds. The Cocoa dictionary + // parser only reads `shutdownTimeInterval`, so without this mapping the JS option is ignored on + // iOS and the native default is always used. + id shutdownTimeoutValue = [mutableOptions valueForKey:@"shutdownTimeout"]; + if ([shutdownTimeoutValue isKindOfClass:[NSNumber class]]) { + sentryOptions.shutdownTimeInterval = [shutdownTimeoutValue doubleValue] / 1000.0; + } + return sentryOptions; }