Skip to content
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

Trigger resumeSubscriptions only if there are subscriptions #641

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ func (c *Client) monitor(ctx context.Context) {
c.pauseSubscriptions(ctx)

var (
subsToRepublish []uint32 // subscription ids for which to send republish requests
subsToRecreate []uint32 // subscription ids which need to be recreated as new subscriptions
availableSeqs map[uint32][]uint32
subsToRepublish []uint32 // subscription ids for which to send republish requests
subsToRecreate []uint32 // subscription ids which need to be recreated as new subscriptions
availableSeqs map[uint32][]uint32 // available sequence numbers per subscription
activeSubs int // number of active subscriptions to resume/recreate
)

for action != none {
Expand Down Expand Up @@ -485,11 +486,13 @@ func (c *Client) monitor(ctx context.Context) {
// Assume that subsToRecreate and subsToRepublish have been
// populated in the previous step.

activeSubs = 0
for _, id := range subsToRepublish {
if err := c.republishSubscription(ctx, id, availableSeqs[id]); err != nil {
dlog.Printf("republish of subscription %d failed", id)
subsToRecreate = append(subsToRecreate, id)
}
activeSubs++
}

for _, id := range subsToRecreate {
Expand All @@ -498,6 +501,7 @@ func (c *Client) monitor(ctx context.Context) {
action = recreateSession
continue
}
activeSubs++
}

c.setState(Connected)
Expand All @@ -521,9 +525,14 @@ func (c *Client) monitor(ctx context.Context) {
<-c.sechanErr
}

dlog.Printf("resuming subscriptions")
c.resumeSubscriptions(ctx)
dlog.Printf("resumed subscriptions")
switch {
case activeSubs > 0:
dlog.Printf("resuming %d subscriptions", activeSubs)
c.resumeSubscriptions(ctx)
dlog.Printf("resumed %d subscriptions", activeSubs)
default:
dlog.Printf("no subscriptions to resume")
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions client_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ publish:

default:
// send publish request and handle response
//
// publish() blocks until a PublishResponse
// is received or the context is cancelled.
if err := c.publish(ctx); err != nil {
dlog.Print("error: ", err.Error())
c.pauseSubscriptions(ctx)
Expand Down