ros2dart / dartros1

A ROS1 client library for dart
Apache License 2.0
20 stars 11 forks source link

NamedSocket.name called after close, throwing exception #3

Closed knuesel closed 3 years ago

knuesel commented 3 years ago

Letting dartros_example.dart run for a few seconds, then pressing Ctrl-C gives the following:

value
true
new value
^CUnhandled exception:
SocketException: Socket has been closed
#0      _NativeSocket.remoteAddress (dart:io-patch/socket_patch.dart:1044:32)
#1      _RawSocket.remoteAddress (dart:io-patch/socket_patch.dart:1661:48)
#2      _Socket.remoteAddress (dart:io-patch/socket_patch.dart:1987:16)
#3      NamedSocket.name (package:dartros/src/utils/tcpros_utils.dart:368:25)
#4      PublisherImpl.handleSubscriberConnection.<anonymous closure> (package:dartros/src/impl/publisher_impl.dart:144:36)
...

The problem appears to be that publisher_impl.dart can do subClients.remove(connection.name) when the socket is already closed. This throws when the name extension method calls remoteAddress on the socket.

TimWhiting commented 3 years ago

Yes, I've been seeing this too. I think I might have to wrap the socket in a class that also contains the 'name' as it was when the connection was first made. I don't have a lot of time to fix it right now, since I have other priorities, and this isn't a big issue since it is only when the node is being shutdown, but it would be nice to have a more clean shutdown. Let me know if you want to take a look into implementing a fix, and if not I'll try to get to it eventually.

knuesel commented 3 years ago

OK, I'll propose a fix.