-
Notifications
You must be signed in to change notification settings - Fork 95
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
autopaho RPC Handler breaks on reconnections #124
Comments
I'm somewhat reluctant to add this because it's something that can be handled fairly easily in the
Again this introduces complexity (potential deadlocks, change requested whilst callbacks are being called) and could lead to intermittent hard to locate bugs (often in the end users code). It also ties the user to one implementation which would probably lead to more options (e.g. are callbacks called in series or goroutines, what happens if the connection drops while callbacks are in progress etc). An alternative approach would be to (very draft!):
I think this would be a relatively simple approach (fairly easy for the end user to understand, no magic and easy for the user to replace if their use case differed - e.g. should callbacks be called in one goroutine or separate goroutines). A benefit (from my perspective) is that it would not require any changes to autopaho itself. Note that I'm not saying no to your ideas; I'm just very cautions when it comes to adding options due to my experience managing the v3.1.1 client which is really complex due to options added over the years. |
That's actually not too bad of an idea. I might go ahead and implement it this way! It does do have the benefit of allowing you a simple OnConnectionUp callback (when not using The downside is that it will be a slightly less convenient API for my use case, but I think can live with making my own helper func that sets up Where would this ConnectionUpManager belong in the source code tree if I go ahead and implement it? Directly under autopaho under What about generalizing it as a |
Further question: What do you think about having |
Some shower thoughts later, I'm starting to find some potential issues: Another particular issue we will see when going with the callback-approach -- opposed to having auto-resubscribe functionality built-in to autopaho -- is when creating the RPC handler it currently subscribes directly (it assumes connection is up). With subscribing on a callback we will have to figure out whether we are already up or not in the This might need a goroutine in the handler that subscribes immediately if it is currently up, but waits on connection. After this it would need to block until next reconnection (blocking even if currently online) before doing Subscribe again... Some channel like This makes me start thinking that it might be better to handle this complexity directly in autopaho with an auto-resubscribe funtionality or perhaps it can be made external in a similar way to the proposed |
The best approach here will depend upon your use-case. In many cases you would want to wait until
As I said previously I'm not averse to looking at your proposed approach; however I just wanted to caution you that any changes to the library should add minimal complexity and ideally not force users to take a particular approach (that leads to the need for yet more options :-) ). Please do feel free to submit a PR and we can discuss at that point (but I don`t want you to do too much work without an understanding of how it will be assessed - really want to avoid a repeat of the 3.1.1 client...).
Be cautious with this; when operating at QOS1+/Cleansession=False subscriptions survive a disconnect/reconnect (e.g. application restart). A common issue with the 3.1.1. client is that users just call |
EDIT: See post after this one first So I started out trying to make the auto-resubcription feature as a separate structure that could plug in to autopaho just to see where it would go and what issues I'd run into. The main issue I bumped into was that I'd need some way to execute code before The idea with the Note that even a simpler solution to response topic re-subscription that ultimately relies on I might make another go at fixing this using the simpler API you proposed. This would likely be the least messy, although it would kind of depend on #116 and For reference this is the API and implementation I thus far came up with (a bit rough still, I mostly wrote it to sort my thoughts out so it's not complete, and the lock usage might not be correct or optimal yet):
|
Another route entirely: Remove the handling of subscribing to the response topic from Problem: Need to make sure RPC response handler is in router before subscription. Meaning likely the RPC handler will not be handling this as well, leaving it up to the user to register this too. Likely means we end up with some circular reference fun that needs to be worked around. This ends up being a bit inelegant. |
Version
Latest git version at time of writing.
Describe the bug
The autopaho RPC handler extension provided under
autopaho/extensions/rpc
only callsautopaho.ConnectionManager.Subscribe()
when you callrpc.NewHandler()
. However autopaho currently lacks any mechanism to automatically resubscribe to topics on connection, instead relying on theOnConnectionUp
callback, which can only be supplied at creation withautopaho.NewConnection()
.Now a potential workaround I figured was to recreate the handler in the
OnConnectionUp
callback or perhaps for every single request (randomizing some part of the response topic). However this leads to memory leaks or potentially worse issues as there is no way to un-create an RPC handler once it has already been created. In particular if one is usingpaho.StandardRouter
it will just keep on adding new callbacks for the response topic whenrpc.NewHandler()
callsopts.Router.RegisterHandler(...)
.To reproduce
I run the following test program against mosquitto and another application that can accept RPC calls. Restarting mosquitto or otherwise disturbing the connection between the RPC caller application and the broker causes it to disconnect and reconnect as expected. However after autopaho reconnecting we never re-subscribe to the response topic so we never received the responses from the RPC callee application.
The test program:
Expected behaviour
The autopaho RPC handler should be able to survive reconnects.
Potential solutions
Fixing this would require either:
OnConnectionUp
callbacks on the fly to anautopaho.ConnectionManager
so thatrpc.NewHandler
can add a callback to theConnectionManager
to ensure that the response topic gets re-subscribed in the event of a disconnect and re-connect.I am opening this issue here to get discussion of potential solutions started before I make a PR.
Personally I think number 1 would be more preferrable as I believe the most common usage pattern of autopaho would also benefit from this sort of re-subscribing mechanism. In my experiments I have made a crude version of this which I might refine a bit and send as a PR (but first I need to refine it and also sign the CLA). I can post it as a patch file in this issue if it would help discussion.
The text was updated successfully, but these errors were encountered: