[squeak-dev] Resuming a SocketStream after a ConnectionClosed exception?

David T. Lewis lewis at mail.msen.com
Sun Feb 12 16:10:19 UTC 2017


On Fri, Feb 10, 2017 at 10:01:46PM -0800, tim Rowledge wrote:
> My MQTT stuff needs to handle the occasional ConnectionClosed type error. 
> 
> I don???t see anything in SocketStream code that suggests any sort of reconnect, and indeed the ConnectionClosed exception is non-resumable. What on earth does one do when a socket dies? 
> 

I'm not looking at SocketStream as I write this, but the general answer
to this question is that you should close the old socket and open an
new one. Close the old one to ensure that you do not leak file descriptors,
and open a new one because there is almost never anything else to be
done anyway.

> My two i/o loops are basically  just
> [[outboundSharedQueue next outputOn: socketStream] repeat]
> and
> [[self handleIncoming: (MQTTPacket readFrom: socketStream)] repeat]
> forked off as separate processes.
> 
> The socketStream can raise the ConnectionClosed when either doing the #next as part of the reading, or  in the #nextPut: whilst writing; obviously. Right now I???m trying to make it work with  the read process modified to 
> 
> [[[packet := [MQTTPacket readFrom: socketStream] on: NetworkError do:[:e|
> 	some stuff to reconnect.
> 	e retry].
> self handleIncoming: packet] repeat] forkThing
> 
> What ought to happen is the socket stream gets reconnected/replaced, the MQTT connection is re-established and then the [MQTTPacket readFrom: socketStream] is restarted. There???s some extra fun for dealing with interrupted multi-part handshaking sequences too, but that???s a different colour of fish-kettle.
> 

If you have some kind of object that represents "MQTT connection", that may
be the right place to put the reconnect logic. You'll probably want some kind
of delay to avoid endlessly retrying a connection that is not going to work.

Dave


> Clearly the ???some stuff to reconnect??? is not currently doing the job I thought it was since it doesn???t seem to reconnect and hookup again. I???m beginning to think that I ought to suspend the other process before doing the reconnect, and also that I???ve stared at this so much I???m not seeing the wood for the trees.
> 
> I???m not picking up any particular inspiration from WebClient or WebServer and haven???t googled into anything that seems relevant. Any ideas out there?
> 
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> How many of you believe in telekinesis? Raise my hands....
> 
> 
> 


More information about the Squeak-dev mailing list