Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop failing on double finalization #224

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,44 @@ jobs:
- name: analyze
run: sh ./tool/analyze.sh

- name: dart test
# unit tests:

- name: test leak_tracker
run: dart test
working-directory: pkgs/leak_tracker

- name: dart test
- name: test leak_tracker_testing
run: dart test
working-directory: pkgs/leak_tracker_testing

- name: flutter test
- name: test leak_tracker_flutter_testing
run: flutter test --enable-vmservice
working-directory: pkgs/leak_tracker_flutter_testing

- name: integration test
- name: test memory_usage
run: dart test
working-directory: pkgs/memory_usage

# integration tests:

- name: integration test examples/autosnapshotting
run: flutter test integration_test/app_test.dart -d flutter-tester
working-directory: examples/autosnapshotting

# cycles:

- name: cycles in leak_tracker
run: dart run layerlens --fail-on-cycles
working-directory: pkgs/leak_tracker

- name: cycles in leak_tracker_testing
run: dart run layerlens --fail-on-cycles
working-directory: pkgs/leak_tracker_testing

- name: cycles in leak_tracker_flutter_testing
run: dart run layerlens --fail-on-cycles
working-directory: pkgs/leak_tracker_flutter_testing

- name: cycles in memory_usage
run: dart run layerlens --fail-on-cycles
working-directory: pkgs/memory_usage
2 changes: 1 addition & 1 deletion doc/leak_tracking/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Detecting memory leaks for large applications is hard ([snapshot diffing](https://nodejs.org/en/docs/guides/diagnostics/memory/using-heap-snapshot), [profiling](https://www.atatus.com/blog/how-to-identify-memory-leaks/#:~:text=doomed%20to%20fail.-,Is%20There%20a%20Way%20to%20Tell%20a%20Memory%20Leak%3F,RAM%20and%20crash%20your%20application.)). Normally, the leaks impact users, staying invisible for application teams.

leak_tracker helps to catch memory issues much earlier by detecting not-disposed and not-garbage-collected objects in Flutter regression tests.
`leak_tracker` helps to catch memory issues much earlier by detecting not-disposed and not-garbage-collected objects in Flutter regression tests.

## Read more

Expand Down
4 changes: 4 additions & 0 deletions pkgs/leak_tracker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 10.0.5

* Stop failing if finalization happened twice.

# 10.0.4

* Add exceptions to test helpers.
Expand Down
7 changes: 6 additions & 1 deletion pkgs/leak_tracker/lib/DEPENDENCIES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!---
Generated by https://github.com/polina-c/layerlens
Dependencies that create loop are markes with `!`.
Dependencies that create loops (inversions) are marked with `!`.
-->

```mermaid
Expand All @@ -9,3 +9,8 @@ devtools_integration.dart-->src;
leak_tracker.dart-->src;
```

### Inversions
In this folder: 0

Including sub-folders: 0

8 changes: 6 additions & 2 deletions pkgs/leak_tracker/lib/src/DEPENDENCIES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<!---
Generated by https://github.com/polina-c/layerlens
Dependencies that create loop are markes with `!`.
Dependencies that create loops (inversions) are marked with `!`.
-->

```mermaid
flowchart TD;
devtools_integration-->shared;
leak_tracking-->devtools_integration;
leak_tracking-->shared;
usage_tracking-->shared;
```

### Inversions
In this folder: 0

Including sub-folders: 0

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!---
Generated by https://github.com/polina-c/layerlens
Dependencies that create loop are markes with `!`.
Dependencies that create loops (inversions) are marked with `!`.
-->

```mermaid
Expand All @@ -13,3 +13,8 @@ delivery.dart-->_protocol.dart;
delivery.dart-->primitives.dart;
```

### Inversions
In this folder: 0

Including sub-folders: 0

8 changes: 6 additions & 2 deletions pkgs/leak_tracker/lib/src/leak_tracking/DEPENDENCIES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!---
Generated by https://github.com/polina-c/layerlens
Dependencies that create loop are markes with `!`.
Dependencies that create loops (inversions) are marked with `!`.
-->

```mermaid
Expand All @@ -22,9 +22,13 @@ _object_tracker.dart-->_object_record.dart;
_object_tracker.dart-->_object_records.dart;
_object_tracker.dart-->primitives;
helpers.dart-->primitives;
leak_testing.dart-->primitives;
leak_tracking.dart-->_baseliner.dart;
leak_tracking.dart-->_leak_tracker.dart;
leak_tracking.dart-->primitives;
```

### Inversions
In this folder: 0

Including sub-folders: 0

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class ObjectRecord {
DateTime? _gcedTime;
int? _gcedGcCount;
void setGCed(int gcCount, DateTime time) {
if (_gcedGcCount != null) throw Exception('The object $code GCed twice');
// Normally it should not happen, but sometimes finalizer is called twice.
// To repro, update next line to throw exception and run flutter tests with
// the updated leak_tracker.
if (_gcedGcCount != null) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a TODO with a bug tracking this. The Dart VM really should not be calling finalizers twice.
Do we have a standalone repro so that @rmacnak-google and others on the Dart team can reproduce?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_gcedGcCount = gcCount;
_gcedTime = time;
}
Expand Down
2 changes: 2 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Future<void> forceGC({
///
/// Does not work in web and in release mode.
///
/// To run this inside `flutter test` pass `--enable-vmservice`.
///
/// Also does not work for objects that are not returned by getInstances.
/// https://github.com/dart-lang/sdk/blob/3e80d29fd6fec56187d651ce22ea81f1e8732214/runtime/vm/object_graph.cc#L1803
Future<String?> formattedRetainingPath(WeakReference ref) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ abstract class LeakTracking {
return true;
}());

await (result ?? Future.value());
await (result ?? Future<void>.value());
}

/// Declares all not disposed objects as leaks.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!---
Generated by https://github.com/polina-c/layerlens
Dependencies that create loops (inversions) are marked with `!`.
-->

```mermaid
flowchart TD;
_retaining_path.dart-->_retaining_path_web.dart;
```

### Inversions
In this folder: 0

Including sub-folders: 0

7 changes: 6 additions & 1 deletion pkgs/leak_tracker/lib/src/shared/DEPENDENCIES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!---
Generated by https://github.com/polina-c/layerlens
Dependencies that create loop are markes with `!`.
Dependencies that create loops (inversions) are marked with `!`.
-->

```mermaid
Expand All @@ -11,3 +11,8 @@ shared_model.dart-->_formatting.dart;
shared_model.dart-->_primitives.dart;
```

### Inversions
In this folder: 0

Including sub-folders: 0

4 changes: 2 additions & 2 deletions pkgs/leak_tracker/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: leak_tracker
version: 10.0.4
version: 10.0.5
description: A framework for memory leak tracking for Dart and Flutter applications.
repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker

Expand All @@ -18,5 +18,5 @@ dependencies:

dev_dependencies:
dart_flutter_team_lints: ^2.1.0
layerlens: ^1.0.0
layerlens: ^1.0.16
test: ^1.16.0
4 changes: 4 additions & 0 deletions pkgs/leak_tracker_flutter_testing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.4

* Upgrade leak_tracker to 10.0.5.

## 3.0.3

* Upgrade leak_tracker to 10.0.4.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/leak_tracker_flutter_testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Coming soon! See https://github.com/flutter/devtools/issues/3951.

## What is leak_tracker_flutter_testing?

leak_tracker_flutter_testing is Flutter specific test helpers for [leak_tracker](https://pub.dev/packages/leak_tracker).
`leak_tracker_flutter_testing` is Flutter specific test helpers for [leak_tracker](https://pub.dev/packages/leak_tracker).

They are separated from [leak_tracker_testing](https://pub.dev/packages/leak_tracker_testing) because the last one is pure Flutter
package and should not reference Flutter Framework.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/leak_tracker_flutter_testing/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: leak_tracker_flutter_testing
version: 3.0.3
version: 3.0.4
description: An internal package to test leak tracking with Flutter.
repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker_flutter_testing

Expand All @@ -17,4 +17,5 @@ dependencies:

dev_dependencies:
dart_flutter_team_lints: ^2.1.0
layerlens: ^1.0.16
test: ^1.25.0
2 changes: 1 addition & 1 deletion pkgs/leak_tracker_testing/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies:

dev_dependencies:
dart_flutter_team_lints: ^2.1.0
layerlens: ^1.0.0
layerlens: ^1.0.16
test: ^1.16.0
2 changes: 1 addition & 1 deletion pkgs/memory_usage/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies:

dev_dependencies:
dart_flutter_team_lints: ^2.1.0
layerlens: ^1.0.0
layerlens: ^1.0.16
test: ^1.16.0
Loading