Skip to content

Critical bug in abortTransaction method: Database operations blocked when no parent span exists #3058

Description

@ichiko

Platform

Dart

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.29.2, on macOS 14.6.1 23G93 darwin-arm64, locale ja-JP) [4.4s]
• Flutter version 3.29.2 on channel stable at /Users/ichiko-moro/fvm/versions/3.29.2
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c236373904 (4 months ago), 2025-03-13 16:17:06 -0400
• Engine revision 18b71d647a
• Dart version 3.7.2
• DevTools version 2.42.3

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.9s]
• Android SDK at /Users/ichiko-moro/Library/Android/sdk
✗ cmdline-tools component is missing
Run path/to/sdkmanager --install "cmdline-tools;latest"
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run flutter doctor --android-licenses to accept the SDK licenses.
See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2) [10.1s]
• Xcode at /Applications/Xcode-16.2.0.app/Contents/Developer
• Build 16C5032a
• CocoaPods version 1.16.2

[✓] Chrome - develop for the web [9ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1) [9ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version openjdk version "17.0.11" 2024-04-16

[✓] Connected device (6 available) [7.1s]
• Pixel 6 (mobile) • 1A151FDF6002G9 • android-arm64 • Android 14 (API 34)
• revphone (wireless) (mobile) • 00008110-000628C82130401E • ios • iOS 18.5 22F76
• iPhone SE (3rd generation) (mobile) • 0B6AA5E6-6980-462F-B912-6CC5F5DBE24A • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.6.1 23G93 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.6.1 23G93 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 138.0.7204.93
! Error: Browsing on the local area network for iPhone#11. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [369ms]
• All expected network resources are available.

! Doctor found issues in 1 category.

Version

9.3.0

Steps to Reproduce

Problem

When parentSpan is null (line 147-153), the method logs a warning and returns Future.value() without executing the provided execute function. This means the actual database transaction abort operation is never performed, leaving the database in an inconsistent state where:
The transaction remains open in the database
Subsequent database operations may be blocked
The application may hang or fail on subsequent DB access attempts

Reproductive code

After the throwing exception,

  • Database transactions may remain open indefinitely
  • Subsequent database operations can be blocked
  • Application may hang or crash on database access
  • Data integrity issues may occur
    final sentryTransaction = Sentry.startTransaction(
      'someUseCase',
      'usecase',
      bindToScope: true,
    );
    try {
      final drift = ref.read(driftProvider);

      await drift.transaction(() async {
        throw Exception('test');
      });
    ...

Current problematic code

final parentSpan = _transactionStack.lastOrNull;
if (parentSpan == null) {
_hub.options.log(
SentryLevel.warning,
'Active Sentry transaction does not exist, could not finish span for Drift operation: Abort Transaction',
logger: loggerName,
);
return Future<T>.value();
}

Expected Result

The method should execute the execute function regardless of whether a parent span exists, similar to how beginTransaction and finishTransaction handle this scenario. The Sentry span tracking should be optional and should not prevent the actual database operation from occurring.

Actual Result

no error occurred but database operation is blocked forever.

Are you willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions