Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 15ee76c

Browse files
[flutter_releases] Flutter Dev 2.2.0-10.0.pre Engine Cherrypicks (#25595)
* Made sure not to delete handles of dart objects if the isolate has been deleted (#25506) * Roll Dart SDK to 2.13.0-211.6.beta * update licenses golden Co-authored-by: gaaclarke <[email protected]>
1 parent 56b1355 commit 15ee76c

File tree

11 files changed

+126
-11
lines changed

11 files changed

+126
-11
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ vars = {
3535
# Dart is: https://github.com/dart-lang/sdk/blob/master/DEPS.
3636
# You can use //tools/dart/create_updated_flutter_deps.py to produce
3737
# updated revision list of existing dependencies.
38-
'dart_revision': 'dda1a31495e39a77b463753caf1295eaa47bc983',
38+
'dart_revision': '94162a28126443d4c3f1a7c9267ec1d69d38b330',
3939

4040
# WARNING: DO NOT EDIT MANUALLY
4141
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py

ci/licenses_golden/licenses_third_party

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Signature: 157665685c22d5c88a7863dd84ab95a2
1+
Signature: 0fce0af83c09a7625b27fad90f7ff9eb
22

33
UNUSED LICENSES:
44

runtime/dart_isolate.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
203203
return isolate;
204204
}
205205

206+
void DartIsolate::SpawnIsolateShutdownCallback(
207+
std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
208+
std::shared_ptr<DartIsolate>* isolate_data) {
209+
DartIsolate::DartIsolateShutdownCallback(isolate_group_data, isolate_data);
210+
}
211+
206212
std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
207213
const Settings& settings,
208214
fml::RefPtr<const DartSnapshot> isolate_snapshot,
@@ -267,7 +273,9 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
267273
return Dart_CreateIsolateInGroup(
268274
/*group_member=*/spawning_isolate->isolate(),
269275
/*name=*/(*isolate_group_data)->GetAdvisoryScriptEntrypoint().c_str(),
270-
/*shutdown_callback=*/nullptr,
276+
/*shutdown_callback=*/
277+
reinterpret_cast<Dart_IsolateShutdownCallback>(
278+
DartIsolate::SpawnIsolateShutdownCallback),
271279
/*cleanup_callback=*/nullptr,
272280
/*child_isolate_data=*/isolate_data,
273281
/*error=*/error);

runtime/dart_isolate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ class DartIsolate : public UIDartState {
552552
// |Dart_DeferredLoadHandler|
553553
static Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id);
554554

555+
static void SpawnIsolateShutdownCallback(
556+
std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
557+
std::shared_ptr<DartIsolate>* isolate_data);
558+
555559
FML_DISALLOW_COPY_AND_ASSIGN(DartIsolate);
556560
};
557561

runtime/dart_isolate_unittests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ TEST_F(DartIsolateTest, SpawnIsolate) {
153153
}
154154

155155
ASSERT_TRUE(spawn->Shutdown());
156+
ASSERT_TRUE(spawn->IsShuttingDown());
156157
ASSERT_TRUE(root_isolate->Shutdown());
157158
}
158159

testing/dart_isolate_runner.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@ AutoIsolateShutdown::AutoIsolateShutdown(std::shared_ptr<DartIsolate> isolate,
1313
: isolate_(std::move(isolate)), runner_(std::move(runner)) {}
1414

1515
AutoIsolateShutdown::~AutoIsolateShutdown() {
16+
if (!isolate_->IsShuttingDown()) {
17+
Shutdown();
18+
}
19+
fml::AutoResetWaitableEvent latch;
20+
fml::TaskRunner::RunNowOrPostTask(runner_,
21+
[isolate = std::move(isolate_), &latch]() {
22+
// Delete isolate on thread.
23+
latch.Signal();
24+
});
25+
latch.Wait();
26+
}
27+
28+
void AutoIsolateShutdown::Shutdown() {
1629
if (!IsValid()) {
1730
return;
1831
}
1932
fml::AutoResetWaitableEvent latch;
2033
fml::TaskRunner::RunNowOrPostTask(
21-
runner_, [isolate = std::move(isolate_), &latch]() {
34+
runner_, [isolate = isolate_.get(), &latch]() {
2235
if (!isolate->Shutdown()) {
2336
FML_LOG(ERROR) << "Could not shutdown isolate.";
2437
FML_CHECK(false);

testing/dart_isolate_runner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class AutoIsolateShutdown {
3030

3131
[[nodiscard]] bool RunInIsolateScope(std::function<bool(void)> closure);
3232

33+
void Shutdown();
34+
3335
DartIsolate* get() {
3436
FML_CHECK(isolate_);
3537
return isolate_.get();

third_party/tonic/dart_persistent_value.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ void DartPersistentValue::Clear() {
4343
return;
4444
}
4545

46-
if (Dart_CurrentIsolateGroup()) {
47-
Dart_DeletePersistentHandle(value_);
48-
} else {
49-
DartIsolateScope scope(dart_state->isolate());
50-
Dart_DeletePersistentHandle(value_);
46+
/// TODO(80155): Remove the handle even if the isolate is shutting down. This
47+
/// may cause memory to stick around until the isolate group is destroyed.
48+
/// Without this branch, if DartState::IsShuttingDown == true, this code will
49+
/// crash when binding the isolate.
50+
if (!dart_state->IsShuttingDown()) {
51+
if (Dart_CurrentIsolateGroup()) {
52+
Dart_DeletePersistentHandle(value_);
53+
} else {
54+
DartIsolateScope scope(dart_state->isolate());
55+
Dart_DeletePersistentHandle(value_);
56+
}
5157
}
58+
5259
dart_state_.reset();
5360
value_ = nullptr;
5461
}

third_party/tonic/tests/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ executable("tonic_unittests") {
1515
public_configs = [ "//flutter:export_dynamic_symbols" ]
1616

1717
sources = [
18+
"dart_persistent_handle_unittest.cc",
1819
"dart_state_unittest.cc",
1920
"dart_weak_persistent_handle_unittest.cc",
2021
]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/testing/dart_isolate_runner.h"
6+
#include "flutter/testing/fixture_test.h"
7+
8+
namespace flutter {
9+
namespace testing {
10+
11+
class DartPersistentHandleTest : public FixtureTest {
12+
public:
13+
DartPersistentHandleTest()
14+
: settings_(CreateSettingsForFixture()),
15+
vm_(DartVMRef::Create(settings_)),
16+
thread_(CreateNewThread()),
17+
task_runners_(GetCurrentTestName(),
18+
thread_,
19+
thread_,
20+
thread_,
21+
thread_) {}
22+
23+
~DartPersistentHandleTest() = default;
24+
25+
[[nodiscard]] bool RunWithEntrypoint(const std::string& entrypoint) {
26+
if (running_isolate_) {
27+
return false;
28+
}
29+
auto isolate = RunDartCodeInIsolate(vm_, settings_, task_runners_,
30+
entrypoint, {}, GetFixturesPath());
31+
if (!isolate || isolate->get()->GetPhase() != DartIsolate::Phase::Running) {
32+
return false;
33+
}
34+
35+
running_isolate_ = std::move(isolate);
36+
return true;
37+
}
38+
39+
protected:
40+
Settings settings_;
41+
DartVMRef vm_;
42+
std::unique_ptr<AutoIsolateShutdown> running_isolate_;
43+
fml::RefPtr<fml::TaskRunner> thread_;
44+
TaskRunners task_runners_;
45+
FML_DISALLOW_COPY_AND_ASSIGN(DartPersistentHandleTest);
46+
};
47+
48+
TEST_F(DartPersistentHandleTest, ClearAfterShutdown) {
49+
auto persistent_value = tonic::DartPersistentValue();
50+
51+
fml::AutoResetWaitableEvent event;
52+
AddNativeCallback("GiveObjectToNative",
53+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
54+
auto handle = Dart_GetNativeArgument(args, 0);
55+
56+
auto dart_state = tonic::DartState::Current();
57+
ASSERT_TRUE(dart_state);
58+
ASSERT_TRUE(tonic::DartState::Current());
59+
persistent_value.Set(dart_state, handle);
60+
61+
event.Signal();
62+
}));
63+
64+
ASSERT_TRUE(RunWithEntrypoint("callGiveObjectToNative"));
65+
event.Wait();
66+
67+
running_isolate_->Shutdown();
68+
69+
fml::AutoResetWaitableEvent clear;
70+
task_runners_.GetUITaskRunner()->PostTask([&] {
71+
persistent_value.Clear();
72+
clear.Signal();
73+
});
74+
clear.Wait();
75+
}
76+
} // namespace testing
77+
} // namespace flutter

0 commit comments

Comments
 (0)