daniel-naegele / upnp.dart

UPnP Client for Dart
MIT License
13 stars 2 forks source link

Configurable timeouts #8

Open kostadin24 opened 1 year ago

kostadin24 commented 1 year ago

Hello From time to time I see timeouts:

TimeoutException after 0:00:10.000000: Future not completed - http://192.168.1.104/2_v4_upnp_device_desc.xml TimeoutException after 0:00:10.000000: Future not completed - http://192.168.1.113:6661/ TimeoutException after 0:00:10.000000: Future not completed - http://192.168.1.1:49152/IGDdevicedesc.xml TimeoutException after 0:00:10.000000: Future not completed - http://192.168.1.1:49154/description.xml

It happens on random manner. Sometimes I see them, sometime not. I saw timeout values in library, but can not find way to configure them. Most frequently I see this for router. Like too much services to process. Can we configure timeouts?

daniel-naegele commented 1 year ago

Do you have some more logs? Any code for reproducing the error?

kostadin24 commented 1 year ago

Future<List> findAllServices(int secondsDuration) async { if (_loggingEnabled) print('### ${DateTime.now()} Start SSDP scan');

DeviceDiscoverer discoverer = DeviceDiscoverer();
final Duration duration = Duration(seconds: secondsDuration);
await discoverer.start(ipv4: true, ipv6: false);

List<SSDPService> services = [];

discoverer.quickDiscoverClients().listen((client) async {
try {
  final dev = await client.getDevice();
  if (dev != null) {
    var metadata = _parseMetadata(dev);
    services.add(SSDPService(dev.friendlyName ?? '', dev.deviceType ?? '', dev.url ?? '', metadata, 'SSDP', dev.manufacturer, dev.modelName));
 }
} catch (e) {
    print('[SSDPServiceDiscoverer] ERROR: $e - ${client.location} ');
}
});

await Future.delayed(duration);

discoverer.stop();
if (_loggingEnabled)
  print('### ${DateTime.now()} End SSDP scan');
return services;

}

kostadin24 commented 1 year ago

Strange moment is that if I replace: discoverer.quickDiscoverClients().listen((client) async { with List<DiscoveredClient> clients = await discoverer.quickDiscoverClients().toList(); no more timeouts printed in logs. Like Flutter can not handle too many async calls in parallel. Waiting to get list and then to call getDevice is longer, but in my case fixes the issue.

daniel-naegele commented 1 year ago

That seems odd, but configurable timeouts still seem like a good enhancement.