Repository: flutter
Issue: Crash in [FlutterEngine destroyContext], Shell.reset()
Labels: platform-ios,engine,a: accessibility,P2,c: fatal crash,customer: huggsy (g3),team-ios,triaged-ios

Cross posted from internal bug b/256086107

We're seeing a crash with about ~130 reports per day for Google customer Huggsy. There's no repro, but I wonder if there's enough detail in the stack trace to figure it out. The crash seems to happen during app termination (UIApplication _terminateWithStatus is in the stack trace), making it especially difficult to repro. I guess it's a memory management issue seeing as the crash is in objc_release?

<details>
<summary>Stack trace</summary>

```
Stack Trace:
0x0000000184acf680 ( libobjc.A.dylib + 0x00003680 ) objc_release
0x00000001d2e2e61c ( libsystem_blocks.dylib + 0x0000161c ) _call_dispose_helpers_excp
0x00000001d2e2e2b4 ( libsystem_blocks.dylib + 0x000012b4 ) _Block_release
0x00000001d2e2e61c ( libsystem_blocks.dylib + 0x0000161c ) _call_dispose_helpers_excp
0x00000001d2e2e2b4 ( libsystem_blocks.dylib + 0x000012b4 ) _Block_release
0x000000010516f07c ( Flutter - /opt/s/w/ir/cache/builder/src/out/ios_release/../../flutter/fml/platform/darwin/scoped_block.h:46 ) void std::__1::allocator_traits<std::__1::allocator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, flutter::PlatformMessageHandlerIos::HandlerInfo>, void*>>>::destroy<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, flutter::PlatformMessageHandlerIos::HandlerInfo>>(std::__1::allocator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, flutter::PlatformMessageHandlerIos::HandlerInfo>, void*>>&, std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, flutter::PlatformMessageHandlerIos::HandlerInfo>*)
0x000000010516f02c ( Flutter - /opt/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__hash_table:1602 ) std::__1::__hash_table<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, flutter::PlatformMessageHandlerIos::HandlerInfo>, std::__1::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, flutter::PlatformMessageHandlerIos::HandlerInfo>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, true>, std::__1::__unordered_map_equal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, flutter::PlatformMessageHandlerIos::HandlerInfo>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, true>, std::__1::allocator<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, flutter::PlatformMessageHandlerIos::HandlerInfo>>>::~__hash_table()
0x000000010516e330 ( Flutter - /opt/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__hash_table:1533 ) flutter::PlatformMessageHandlerIos::~PlatformMessageHandlerIos()
0x00000001054d41f8 ( Flutter - /opt/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3346 ) flutter::Shell::~Shell()
0x0000000105141238 ( Flutter - /opt/s/w/ir/cache/builder/src/out/ios_release/../../flutter/shell/common/shell.cc:458 ) std::__1::unique_ptr<flutter::Shell, std::__1::default_delete<flutter::Shell>>::reset(flutter::Shell*)
0x000000010513ccd0 ( Flutter - /opt/s/w/ir/cache/builder/src/out/ios_release/../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm:428 ) -[FlutterEngine destroyContext]
0x00000001866bab40 ( CoreFoundation + 0x00034b40 ) __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
0x000000018675a0cc ( CoreFoundation + 0x000d40cc ) ___CFXRegistrationPost_block_invoke
0x000000018673eb74 ( CoreFoundation + 0x000b8b74 ) _CFXRegistrationPost
0x00000001866ce304 ( CoreFoundation + 0x00048304 ) _CFXNotificationPost
0x0000000185a734e8 ( Foundation + 0x000574e8 ) -[NSNotificationCenter postNotificationName:object:userInfo:]
0x000000018e264c44 ( UIKitCore + 0x00c6ac44 ) -[UIApplication _terminateWithStatus:]
0x000000018d86aad8 ( UIKitCore + 0x00270ad8 ) -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
0x000000018dc459e4 ( UIKitCore + 0x0064b9e4 ) -[_UISceneLifecycleMultiplexer forceExitWithTransitionContext:scene:]
0x000000018e261360 ( UIKitCore + 0x00c67360 ) -[UIApplication workspaceShouldExit:withTransitionContext:]
0x000000019fca0384 ( FrontBoardServices + 0x0003b384 ) __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke_2
0x000000019fc6af6c ( FrontBoardServices + 0x00005f6c ) -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
0x000000019fca0328 ( FrontBoardServices + 0x0003b328 ) __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke
0x00000001923b67c4 ( libdispatch.dylib + 0x000647c4 ) _dispatch_client_callout
0x000000019238e404 ( libdispatch.dylib + 0x0003c404 ) _dispatch_block_invoke_direct$VARIANT$armv81
0x000000019fc74470 ( FrontBoardServices + 0x0000f470 ) __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
0x000000019fc740ac ( FrontBoardServices + 0x0000f0ac ) -[FBSSerialQueue _targetQueue_performNextIfPossible]
0x000000019fc76570 ( FrontBoardServices + 0x00011570 ) -[FBSSerialQueue _performNextFromRunLoopSource]
0x00000001867522b4 ( CoreFoundation + 0x000cc2b4 ) __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
0x000000018675dc14 ( CoreFoundation + 0x000d7c14 ) __CFRunLoopDoSource0
0x00000001866e7fa4 ( CoreFoundation + 0x00061fa4 ) __CFRunLoopDoSources0
0x00000001866fcfac ( CoreFoundation + 0x00076fac ) __CFRunLoopRun
0x0000000186701b78 ( CoreFoundation + 0x0007bb78 ) CFRunLoopRunSpecific
0x00000001c0a8d980 ( GraphicsServices + 0x00001980 ) GSEventRunModal
0x000000018d96f3c4 ( UIKitCore + 0x003753c4 ) -[UIApplication _run]
0x000000018d96f03c ( UIKitCore + 0x0037503c ) UIApplicationMain
```
</details>