-
Notifications
You must be signed in to change notification settings - Fork 75
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
✨ retry connecting the cloudevents client #280
✨ retry connecting the cloudevents client #280
Conversation
/assign @qiujian16 |
/hold |
344c2bf
to
89b4d02
Compare
2ac7fb0
to
f27e8ba
Compare
/unhold |
cloudevents/generic/baseclient.go
Outdated
// TODO enhance the cloudevents SKD to avoid wrapping the error type, then we can only handle the | ||
// net connection errors here | ||
klog.Errorf("failed to reconnect, %v", err) | ||
<-connBackoffManager.Backoff().C() |
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.
if it goes into this branch, will it hang on the select in the next loop?
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.
the select in the next loop need to wait the backoff, the backoff is a blocking action
cloudevents/generic/baseclient.go
Outdated
if receiverCancel != nil { | ||
receiverCancel() | ||
} | ||
retrying = true |
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.
can we just set c.cloudEventsClient = nil here?
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.
the cloudEventsClient is also used by send method, if we set it to nil
here, the send may meet the nil pointer, so I did not set it to nil, what's your suggestion?
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.
even though, the send will fail right? I think there might need a rwlock in send otherwise there is always a change that the two threads race.
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 mean after backoff it will go to select in the next loop while client is not instantiated, and it will not have a chance to receive message from c.cloudEventsErrChan
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.
yes, the send will be fail, we maybe need a lock here for the client
the c.cloudEventsErrChan will be only send by a running client, so if the client is retrying, the select will not be blocked the next retry
b58b1c2
to
d9de5d7
Compare
cloudevents/generic/baseclient.go
Outdated
|
||
for { | ||
if cloudEventsClient == nil { | ||
klog.V(4).Infof("reconnecting the cloudevents client") |
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.
one thing missing is: what if the client just send but not subscribe? Do we alway assume that the client will send and subscribe together?
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.
hm... I'm not sure, maybe we cannot assume this, in our case, it seems that for our case the send and sub are always together, but as a lib, we don't stop to separate the send and subscribe, user can send in one process, and sub in other process, maybe we need to have one retry mechanism for the client
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.
separate the reconnect part from the subscription, PTAL
264e03f
to
4c4356b
Compare
|
||
type receiveFn func(ctx context.Context, evt cloudevents.Event) | ||
|
||
type baseClient struct { |
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.
should we have a separated Connect(ctx context.Context) in baseClient? so we do not start goroutine during new?
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.
use connect method instead of new method
Signed-off-by: Wei Liu <liuweixa@redhat.com>
4c4356b
to
d80ec98
Compare
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qiujian16, skeeey The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Maybe @yanmxa or @morvencao could also take a look |
// make sure the current client is the newest | ||
c.RLock() | ||
cloudEventsClient = c.cloudEventsClient | ||
c.RUnlock() |
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.
do we still need to lock it here? since it is locked at the beginning of the subscribe function
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.
yes, we need it, the beginning lock is for the subscribe function (it ensure there is only one subscription go routine running), this lock is in a independent go routine (the subscribe lock will be released after this go routine starts)
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.
emm, right, thanks for the explanation.
looks good to me, leave this to @yanmxa |
Reference: cloudevents/sdk-go#940 /LGTM |
c2b66fa
into
open-cluster-management-io:main
Summary
Retry connecting the cloudevents client when the client has network error