Skip to content

Make sure net/api/client.Subscribe loop ends gracefully when client is closing #515

@merlinran

Description

@merlinran

When client.Close is called, the gRPC connection gets closed, and the stream.Recv() call here returns a gRPC internal error ErrConnClosing, which is not considered a grace close, hence causes a log.Fatalf().

2021/05/14 13:07:05 error in subscription stream: rpc error: code = Unavailable desc = transport is closing

resp, err := stream.Recv()
if err == io.EOF {
return
}
if err != nil {
stat := status.Convert(err)
if stat.Code() != codes.Canceled {
log.Fatalf("error in subscription stream: %v", err)
}
return
}

This shouldn't be considered a fatal error, but maybe more importantly, provide a way to signal the loop to return immediately?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions