-
Notifications
You must be signed in to change notification settings - Fork 6
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
NewStateMapConnection context support? #14
Comments
The intention of current handling is to simply "expect the unexpected" – both intentionally closing the network (in this case done via calling Now further thoughts about synchronized closure of network connections and/or using contexts: If you want to transfer the responsibility to this library, just using a context object is not enough as it does not provide a way to pass cancellation to other objects alone; you still need Aside from that, implementing support for I'm currently unfortunately a bit limited on time that I can spend on this myself to further consider how this would need to be integrated, especially since this project has assumed a sort of Proof of Concept/reference state for other projects to implement the protocol properly. I'm currently leaning, as a result of above thoughts, towards not implementing this, however if there is a stronger take on this with good reasoning I may reconsider my opinion. |
As usual, thanks for your thoughtful analysis and assessment. It is truly appreciated. My general approach for establishing multiple StateMap connections to multiple devices is to launch a goroutine for each connection and have each one monitor their connection-specific error and state channel. Every launched goroutine is also passed a common state and error channel to publish (in a wrapped struct) what it receives from its corresponding device-specific error and state channel. So something like this:
.... This part of the code makes the assumption that the smCh is always closed when there is an error. (You actually link to this in your comment.) This is probably code smell on my part. Maybe I should change it to a
Then I watch the top-level channels for messages:
If something comes through to the common error channel, we stop monitoring both channels and then close all the TCP connections. I think I am technically leaking goroutines for the still healthy StateMap connection(s). I believe they would all eventually become blocked on writes to the common state channel that no longer has a receiver, and thus would not be able to notice the close on their device-specific state channel that is [presumably?] generated during the "close up shop" attempt of the TCP connections. I hope this made sense and provides some background on why I was pondering how to gracefully close things down in a multi-connection scenario. This approach may just be bad -- I'm not really sure yet. Please let me know if this screams code smell to you. At this point I am really just experimenting with potential multi-statemap connections and how to properly handle failure. |
I've pondered this a bit more and have another approach I'm experimenting with that involves waitgroups. The idea is that when at least one statemap connection goroutine exits, a watchdog goroutine shuts down all the statemap tcp connections. this should force closure of all the channels the other statemap goroutines are receiving from and they should all exit. once every goroutine has exited, a second waitgroup in the watchdog will unblock and then cleanly shutdown the top-level channels the statemap connection goroutines were sending on as they received state map updates from their own connection channels. this then allows program flow control to continue and program shutdown to commence. at least that's the theory!
then we fire off a watchdog goroutine:
and then we range over our top-level state channel the goroutines are sending to:
|
Would it potentially make sense to add context support to
NewStateMapConnection
so that we can receive actx.Done()
or initiate a cancel signal? I'm pondering how to gracefully shutdown multipleStateMapConnection
when one of them closes its send channel due to error. If they all shared a parent context, I was thinking a graceful shutdown could be initiated when the failure of one should initiate a shutdown of all.The text was updated successfully, but these errors were encountered: