Skip to content

[iOS] Flakey race condition between SetSemanticsTreeEnabled and UpdateSemantics #174842

@vashworth

Description

@vashworth

Steps to reproduce

  1. flutter create my_app
  2. cd my_app
  3. et run --config ios_debug_sim_unopt_arm64
  4. Quit the app once it launches
  5. Open my_app/ios/Runner.xcworkspace
  6. In Xcode do Product > Run

Note: Error does not always happen since it's a race condition, you may need to do step 6 multiple times. It is more likely to happen if you setup UIScene in your Info.plist, but I have seen it happen for both. Also, the crash can also happen when running from the Flutter CLI, but running from Xcode is faster and allows you to see the error log.

Expected results

App should run fine when using a local engine

Actual results

App crashes

[FATAL:flutter/shell/platform/darwin/ios/platform_view_ios.mm(156)] Check failed: accessibility_bridge_.

I tried tracing it down and it appears that occasionally FlutterEngine enables semantics before the _handleFrameworkSemanticsEnabledChanged listener is set up.

- (void)enableSemantics:(BOOL)enabled withFlags:(int64_t)flags {
if (!self.platformView) {
return;
}
self.platformView->SetSemanticsEnabled(enabled);
self.platformView->SetAccessibilityFeatures(flags);
}

addSemanticsEnabledListener(_handleFrameworkSemanticsEnabledChanged);

And therefore, the semantics tree is never enabled:

void _handleFrameworkSemanticsEnabledChanged() {
platformDispatcher.setSemanticsTreeEnabled(semanticsEnabled);
}

Likely caused by #174163.

Code sample

Use default flutter create sample app

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel main, 3.36.0-1.0.pre-348, on macOS 15.6.1 24G90 darwin-arm64, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
[✓] Chrome - develop for the web
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Critical issues such as a build break or regressione: local-engine-developmentLocal builds of the engine working betterengineflutter/engine related. See also e: labels.platform-iosiOS applications specificallyteam-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)triaged-accessibilityTriaged by Framework Accessibility team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions