textileio/go-threads

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

merlinran opened this issue · 3 comments

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?

could we check errors.Is(err, ErrConnClosing) and just bail when true?

Nope, ErrConnClosing is defined in an internal package so we don't have access. Didn't check if the error wrapper can be recognizable though. Anyway it should be low priority since it only happens when closing down.

Cool, I thought that since it was capitalized it was exported. Anyway, sgtm!