shamblett / coap

A Coap package for dart
Other
16 stars 13 forks source link

Client retains old requests #187

Closed JosefWN closed 3 months ago

JosefWN commented 3 months ago

It seems that the client is retaining completed requests, causing memory and CPU utilization to grow with time. I have a long-running app in which case it becomes very apparent.

To reproduce, I created a poll_resource.dart and dart run --observe poll_resource.dart where I can see an increasing number of CoapRequest:

import 'dart:async';
import 'package:coap/coap.dart';
import 'config/coap_config.dart';

FutureOr<void> main() async {
  final conf = CoapConfig();
  final baseUri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
  final client = CoapClient(baseUri, config: conf);

  for (var i = 1; i <= 10000; i++) {
    try {
      print('Sending request get /test $i to ${baseUri.host}');
      final response = await client.get(Uri(path: 'test'));
      print('/test response: ${response.payloadString}');
      print('---');
    } on Exception catch (e) {
      print('CoAP encountered an exception: $e');
    }

    await Future<void>.delayed(const Duration(seconds: 1));
  }

  client.close();
}

Currently debugging it...

shamblett commented 3 months ago

Ok, your findings should be interesting.

JosefWN commented 3 months ago

It's the broadcast streams leaking: https://github.com/dart-lang/sdk/issues/26686

PR: https://github.com/shamblett/coap/pull/188

shamblett commented 3 months ago

Great thanks, merged, package re published at version 9.0.3