-
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.
[stable] [vm] Fix leakage of file system watcher related data structures
Closes #52703 TEST=runtime/tests/vm/dart/regress_52703_test.dart Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/309862 Bug: #52703 Change-Id: Idd4b153a9c7b19995f6c6c8bda99b878a21425fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311521 Reviewed-by: Lasse Nielsen <lrn@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
- Loading branch information
Showing
3 changed files
with
80 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
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