diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm index ad7535c83f157..a162fbb64c3cf 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm @@ -6,6 +6,7 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h" #include +#include #include "flutter/fml/synchronization/waitable_event.h" #include "flutter/lib/ui/window/platform_message.h" @@ -668,6 +669,19 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable } } +TEST(EngineTest, ThreadSynchronizerNotBlockingRasterThreadAfterShutdown) { + FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init]; + [threadSynchronizer shutdown]; + + std::thread rasterThread([&threadSynchronizer] { + [threadSynchronizer performCommit:CGSizeMake(100, 100) + notify:^{ + }]; + }); + + rasterThread.join(); +} + } // namespace flutter::testing // NOLINTEND(clang-analyzer-core.StackAddressEscape) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm b/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm index 3afa2d53f3551..cb442ea768ffb 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm @@ -79,6 +79,11 @@ - (void)performCommit:(CGSize)size notify:(nonnull dispatch_block_t)notify { fml::AutoResetWaitableEvent event; { std::unique_lock lock(_mutex); + if (_shuttingDown) { + // Engine is shutting down, main thread may be blocked by the engine + // waiting for raster thread to finish. + return; + } fml::AutoResetWaitableEvent& e = event; _scheduledBlocks.push_back(^{ notify();