Skip to content
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

Killing network during requests causes uncatchable exception #110

Closed
JosefWN opened this issue Jul 12, 2022 · 0 comments · Fixed by #113
Closed

Killing network during requests causes uncatchable exception #110

JosefWN opened this issue Jul 12, 2022 · 0 comments · Fixed by #113

Comments

@JosefWN
Copy link
Contributor

JosefWN commented Jul 12, 2022

We don't seem to check if the socket is bound (send's return value is typically ignored, and it's always -1?), but perhaps this is okay since we have retries anyway. Should we ignore any SocketExceptions thrown by send as well then?

Once this issue is fixed I need to remember to test if the previously bound socket is still usable, or if we need to re-bind after some downtime. Need to think about error handling for observe as well, on re-bind...

Example, turning my wifi off during this loop (testing what happens if I drop off a shaky network temporarily):

FutureOr<void> main() async {
  final conf = CoapConfig();
  final uri = Uri(
    scheme: 'coap',
    host: 'californium.eclipseprojects.io',
    port: conf.defaultPort,
  );
  final client = CoapClient(uri, conf);

  try {
    for (var i = 0; i < 10; i++) {
      print('Sending request $i');
      final resp = await client.get('test');
      if (resp.code != CoapCode.content) {
        print('Request failed!');
      }
      await Future<void>.delayed(const Duration(seconds: 5));
    }
  } on Exception catch (e) {
    print('CoAP encountered an exception: $e');
  }

  client.close();
}
Unhandled exception:
SocketException: Send failed (OS Error: Network is unreachable, errno = 51), address = 0.0.0.0, port = 0
#0      _NativeSocket.send (dart:io-patch/socket_patch.dart:1213:34)
#1      _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:2450:15)
#2      CoapNetworkUDP.send (package:coap/src/network/coap_network_udp.dart:55:16)
#3      CoapEndPoint.sendRequest (package:coap/src/net/coap_endpoint.dart:198:21)
#4      CoapStackBottomLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:162:30)
#5      CoapNextLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:29:10)
#6      CoapAbstractLayer.sendRequest (package:coap/src/stack/coap_abstract_layer.dart:26:15)
#7      CoapReliabilityLayer.sendRequest (package:coap/src/stack/coap_reliability_layer.dart:118:11)
#8      CoapNextLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:29:10)
#9      CoapAbstractLayer.sendRequest (package:coap/src/stack/coap_abstract_layer.dart:26:15)
#10     CoapTokenLayer.sendRequest (package:coap/src/stack/coap_token_layer.dart:35:11)
#11     CoapNextLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:29:10)
#12     CoapAbstractLayer.sendRequest (package:coap/src/stack/coap_abstract_layer.dart:26:15)
#13     CoapBlockwiseLayer.sendRequest (package:coap/src/stack/coap_blockwise_layer.dart:72:13)
#14     CoapNextLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:29:10)
#15     CoapAbstractLayer.sendRequest (package:coap/src/stack/coap_abstract_layer.dart:26:15)
#16     CoapNextLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:29:10)
#17     CoapAbstractLayer.sendRequest (package:coap/src/stack/coap_abstract_layer.dart:26:15)
#18     CoapStackTopLayer.sendRequest (package:coap/src/stack/coap_layer_stack.dart:99:11)
#19     CoapLayerStack.sendRequest (package:coap/src/stack/coap_layer_stack.dart:197:18)
#20     CoapEndPoint.sendEpRequest.<anonymous closure> (package:coap/src/net/coap_endpoint.dart:105:37)
#21     _Executor.scheduleTask (package:executor/src/executor_impl.dart:61:29)
<asynchronous suspension>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant