instrumentisto / medea-jason

Mozilla Public License 2.0
2 stars 2 forks source link

Fix segfault on isolate shutdown #163

Closed alexlapa closed 7 months ago

alexlapa commented 7 months ago

medea#225

Synopsis

Thread 4 Crashed:: io.flutter.ui
0   FlutterMacOS                           0x10a7a501c Dart_HandleFromPersistent + 312
1   libmedea_jason.dylib                   0x102baa88c $medea_jason..platform..dart..transport..WebSocketRpcTransport$u20$as$u20$medea_jason..platform..transport..RpcTransport::send::h4e79a68bb1cd2ffd + 344
2   libmedea_jason.dylib                   0x102b22f04 medea_jason::rpc::websocket::client::WebSocketRpcClient::send_command::h4a8a35a20f623e0a + 168
3   libmedea_jason.dylib                   0x102b5c898 $medea_jason..rpc..rpc_session..WebSocketRpcSession$u20$as$u20$medea_jason..rpc..rpc_session..RpcSession::close_with_reason::h926fa61b82b07dd8 + 416
4   libmedea_jason.dylib                   0x102b9ebd4 core::ptr::drop_in_place$LT$medea_jason..room..InnerRoom::ha131d02d86c86ed5 + 108
5   libmedea_jason.dylib                   0x102b9c74c core::ptr::drop_in_place$LT$core..cell..RefCell$LT$medea_jason..jason..Inner::h0f47d0718bb2b058 + 172
6   libmedea_jason.dylib                   0x102b368dc alloc::sync::Arc$LT$T$C$A::drop_slow::h4bc275aa9831024a + 44
7   FlutterMacOS                           0x10a472908 dart::NativeFinalizer::RunCallback(dart::FinalizerEntry const&, char const*) const + 176
8   FlutterMacOS                           0x10a3cc2b0 dart::Isolate::RunAndCleanupFinalizersOnShutdown() + 576
9   FlutterMacOS                           0x10a3cc79c dart::Isolate::Shutdown() + 216
10  FlutterMacOS                           0x10a7a6dd8 Dart_ShutdownIsolate + 224
11  FlutterMacOS                           0x10a2fb628 flutter::DartIsolate::Shutdown() + 100
12  FlutterMacOS                           0x10a308ee8 flutter::RuntimeController::~RuntimeController() + 152
13  FlutterMacOS                           0x10a3090cc flutter::RuntimeController::~RuntimeController() + 32
14  FlutterMacOS                           0x10a235d80 flutter::Engine::~Engine() + 348

Dart-side websocket is reclaimed by flutter before Room, so when Room tries to send LeaveRoom command in Drop implementation application segfaults. This happens if application is closed during call.

Solution

Integrators should use AppLifecycleListener to explicitly dispose all medea-jason objects before Dart_ShutdownIsolate is called.

But anyway we dont really want to segfault if this recommendation is not followed, so this PR wraps Room's Drop implementation in platfrom::spawn, this will prevent segfault since spawned future will not be completed if isolate is currently shutting down.

Checklist

alexlapa commented 7 months ago

FCM:

Fix segfault on Dart isolate shutdown (#163)