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

Propagate pubsub subscriber errors #185

Merged
merged 3 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Azure/go-autorest/autorest/to v0.2.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/gogo/protobuf v1.2.0 // indirect
github.com/google/go-cmp v0.3.0
github.com/google/uuid v1.1.1
github.com/kelseyhightower/envconfig v1.4.0
Expand Down
15 changes: 10 additions & 5 deletions pkg/cloudevents/transport/pubsub/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (t *Transport) StartReceiver(ctx context.Context) error {
}

cctx, cancel := context.WithCancel(ctx)
defer cancel()
n := len(t.subscriptions)

// Make the channels for quit and errors.
Expand All @@ -280,22 +281,26 @@ func (t *Transport) StartReceiver(ctx context.Context) error {
})
}

// Block for parent context to finish.
<-ctx.Done()
cancel()

// Collect errors and done calls until we have n of them.
errs := []string(nil)
for success := 0; success < n; success++ {
var err error
select {
case err = <-errc:
case <-ctx.Done(): // Block for parent context to finish.
success--
case err = <-errc: // Collect errors
case <-quit:
}
if cancel != nil {
// Stop all other subscriptions.
cancel()
cancel = nil
}
if err != nil {
errs = append(errs, err.Error())
}
}

close(quit)
close(errc)

Expand Down