-
Notifications
You must be signed in to change notification settings - Fork 93
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
improve the subscription life cycle event and add new settings #82
Conversation
@sermojohn this improvement is for the subscription run flow that you suggested. There is no recursive Run call in goroutines. All events are centralized in the main loop to control the retry behavior. |
@@ -257,58 +306,75 @@ type handlerFunc func(data []byte, err error) error | |||
|
|||
// Subscription stores the subscription declaration and its state | |||
type Subscription struct { | |||
id string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between id and the key, so to have both per subscription?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see but looking up the subscription either by the key or the id seems complicating, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can separate them into 2 functions. However, I just unify the search function into a single function. We still need to find the subscription by id internally but the user only has the original id before resetting.
Nice improvement! I ran our test-suite, but having some issue. This could be due to the synchronisation, I need to check further. How should the library handle
|
I assume that the client should wait until the cleanup process is done. Anyway, I'll fix this |
@@ -634,14 +634,14 @@ func (sc *SubscriptionClient) doRaw(query string, variables map[string]interface | |||
// if the websocket client is running and acknowledged by the server | |||
// start subscription immediately | |||
ctx := sc.getContext() | |||
if ctx != nil && ctx.GetAcknowledge() { | |||
if ctx != nil && sc.getClientStatus() == scStatusRunning && ctx.GetAcknowledge() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Taken that we do not lock, there are still chances that Subscribe
will be triggered on a closed connection.
But this seems correct to me, based on existing logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found any absolute approach to solve this race condition issue. However, the chance is low except the user tries to close and run repeatedly in parallel. IMO it's better to create a new client and subscribe because all subscriptions were cleared after the client was closed. There isn't any benefit over the new client.
Fix #80
The PR improves the subscription client with a new event and settings
Event
Settings