go-threads icon indicating copy to clipboard operation
go-threads copied to clipboard

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

Open merlinran opened this issue 4 years ago • 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

https://github.com/textileio/go-threads/blob/5d09258e40a4e008cab2d4de9bbeb6ffd5357054/net/api/client/client.go#L297-L307

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

merlinran avatar May 14 '21 13:05 merlinran

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

sanderpick avatar May 14 '21 19:05 sanderpick

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.

merlinran avatar May 14 '21 19:05 merlinran

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

sanderpick avatar May 14 '21 19:05 sanderpick