-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm] Fix leakage of file system watcher related data structures
Closes #52703 TEST=runtime/tests/vm/dart/regress_52703_test.dart Change-Id: Ia76c721a3d3a1466ed1c2e7bd847c331cee95ed7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309862 Reviewed-by: Lasse Nielsen <lrn@google.com> Auto-Submit: Martin Kustermann <kustermann@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
- Loading branch information
1 parent
ac06671
commit 3dd9389
Showing
2 changed files
with
78 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:developer'; | ||
import 'dart:io'; | ||
|
||
import 'package:expect/expect.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:vm_service/vm_service.dart'; | ||
|
||
import 'use_flag_test_helper.dart'; | ||
import '../../../tools/heapsnapshot/lib/src/analysis.dart'; | ||
|
||
void main() async { | ||
if (buildDir.contains('Product')) return; | ||
|
||
final dir = Directory('sdk'); | ||
|
||
StreamSubscription? current; | ||
Future<void> iterate() async { | ||
final temp = dir.watch().listen((event) {}); | ||
await current?.cancel(); | ||
current = dir.watch().listen((event) {}); | ||
await temp.cancel(); | ||
} | ||
|
||
Future<void> finish() async { | ||
await current?.cancel(); | ||
} | ||
|
||
await withTempDir('ama-test', (String tempDir) async { | ||
await iterate(); | ||
|
||
final before = countInstances(tempDir, '_BroadcastSubscription'); | ||
print('Before = $before'); | ||
for (int i = 0; i < 100; i++) { | ||
await iterate(); | ||
} | ||
final after = countInstances(tempDir, '_BroadcastSubscription'); | ||
print('After = $after'); | ||
|
||
await finish(); | ||
|
||
Expect.equals(0, (after - before)); | ||
}); | ||
} | ||
|
||
int countInstances(String tempDir, String className) { | ||
final snapshotFile = path.join(tempDir, 'foo.heapsnapshot'); | ||
NativeRuntime.writeHeapSnapshotToFile(snapshotFile); | ||
final bytes = File(snapshotFile).readAsBytesSync(); | ||
File(snapshotFile).deleteSync(); | ||
final graph = HeapSnapshotGraph.fromChunks( | ||
[bytes.buffer.asByteData(bytes.offsetInBytes, bytes.length)]); | ||
final analysis = Analysis(graph); | ||
return analysis | ||
.filterByClassPatterns(analysis.reachableObjects, [className]).length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters