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

fix(pubsub): hide context.Cancelled error in sync pull #3752

Merged
merged 5 commits into from Mar 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pubsub/iterator.go
Expand Up @@ -247,6 +247,8 @@ func (it *messageIterator) pullMessages(maxToPull int32) ([]*pb.ReceivedMessage,
switch {
case err == context.Canceled:
return nil, nil
case status.Code(err) == codes.Canceled:
codyoss marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil
case err != nil:
return nil, err
default:
Expand Down
21 changes: 21 additions & 0 deletions pubsub/iterator_test.go
Expand Up @@ -400,3 +400,24 @@ func TestIterator_ModifyAckContextDeadline(t *testing.T) {
t.Fatal(err)
}
}

func TestIterator_SynchronousPullCancel(t *testing.T) {
srv := pstest.NewServer()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

srv.Publish(fullyQualifiedTopicName, []byte("creating a topic"), nil)

_, client, err := initConn(ctx, srv.Addr)
if err != nil {
t.Fatal(err)
}
iter := newMessageIterator(client.subc, fullyQualifiedTopicName, &pullOptions{})

// Cancelling the iterator and pulling should not result in any errors.
iter.cancel()

if _, err := iter.pullMessages(100); err != nil {
t.Fatalf("Got error in pullMessages: %v", err)
}
}