-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Memory leak when spawning isolates that use HTTP #59937
Comments
Are you sure it is a memory leak and not a higher peak memory usage? Each time you invoke |
@mraleph Thank you for the response. We've been trying to debug a leak on our Dart server the last weeks, where memory was starting to grow slowly but steadily. We've used a 1GB RAM configuration, and it never stopped growing until reaching the max memory and Cloud Run starting a new instance because of OOM. We will still need to wait a couple of days to see if a recent deploy without One thing we've been wondering while debugging these past weeks, is the implications of setting the VM flag |
The endpoint on our server where we use Isolate.run is only called on some occasions, the reproduction stress script is not a representation of how our server was processing these requests, but it shows the memory growth without garbage collecting. On my local machine it kept growing past 3 GB, even when constraining the old heap size flag. |
As a follow up, since we removed the |
I can confirm that there is indeed a leak inside our HTTPS stack. The repro is like this: import 'dart:io';
import 'dart:isolate';
import 'package:http/http.dart' as http;
Future<void> fetchResponse() async {
return await Isolate.run(() async {
try {
final apiURL = "https://cache-test.skilldevs.com/sample-json.json";
final externalApiRes = await http.get(Uri.parse(apiURL));
if (externalApiRes.statusCode != 200) {
throw Exception("Invalid status code ${externalApiRes.statusCode}");
}
} catch (e) {
throw Exception("Failed to fetch data: $e");
}
});
}
void main() async {
while (true) {
await fetchResponse();
final rssMb = ((ProcessInfo.currentRss) / (1024 * 1024)).toStringAsFixed(2);
print('RSS: ${rssMb} Mb');
await Future.delayed(const Duration(milliseconds: 100));
}
} Native side of the SSL filter implementation is holding a bunch of things strongly via persistent handles, including This state is supposed to be cleared via However if filter is active (e.g. we have sent a request to the filter via That's where There are at least two problems with this code - first one is ownership cycle between Footnotes
|
Dart version:
Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "linux_x64"
On our production shelf server, deployed on Cloud Run, we've discovered a memory leak. The leak happens when using
Isolate.run
and inside the isolate callback we fetch data from an external endpoint using thehttp
package.Here is a reproduction repository: https://github.com/davidmartos96/dart-isolate-http-leak
The RSS memory will rapidly grow with the
cli.dart
andstress_server.dart
scripts provided. The scripts also provide a way to disable the isolate to see the difference.Cloud Run visualization
The text was updated successfully, but these errors were encountered: