dart_amqp icon indicating copy to clipboard operation
dart_amqp copied to clipboard

Expose client socket to handle errors

Open scottk opened this issue 5 years ago • 2 comments

Hi,

Is it possible to expose the socket in ClientImpl to handle errors? At present, if the client disconnects after establishing a connection, there is no way of knowing. If the socket could be exposed, we could add on socket events to handle such events and re-establish the connection.

Is this possible? If not, are there better ways of doing this? Thanks!

scottk avatar Jun 23 '20 12:06 scottk

When the client loses connection to the server, any write attempt should fail with a socket error. I am not sure how the onDone callback for sockets is implemented internally but given that the connection is bi-directional if your client blocks until you receive a message from rabbit, you might not be able to detect that the socket has been disconnected.

In my view, the best way to detect and surface disconnects is by implementing heartbeats as specified by the amqp spec.

On a side-note, even if the client exposed the socket, simply reconnecting would not be sufficient to resume operation; you would still need to re-define any channels and subscribers. This is the primary reason why it wasn't implemented in the client from the start.

achilleasa avatar Jun 26 '20 16:06 achilleasa

Hi thanks for the response. Yeah in other languages we use amqp for we re-define the network topology manually, so that isn't too much of an issue. We use a TCP keep-alive spec rather than heartbeats, which should throw some sort of socket error nearly immediately open loss of connection, but for some reason I only get an internal 60 second timeout that is uncatchable. Would need to do some more digging if Dart has socket event listeners to then project those out of your library

scottk avatar Jun 26 '20 23:06 scottk