plugins: squelch context Canceled error logs

As far as I can tell this is the most straightforward and resilient way
to skip error logging on context cancellation with grpc streams. You
cannot compare the error against context.Canceled directly as it is of
type `*status.statusError`. The next best solution I found was:

```go
resp, err := stream.Recv()
if code, ok := err.(interface{ Code() code.Code }); ok {
	if code.Code == code.Canceled {
		return
	}
}
```

However I think checking ctx.Err() directly makes the code much easier
to read and is resilient against grpc API changes.
This commit is contained in:
Michael Schurter
2019-02-21 11:55:01 -08:00
parent 234f644b35
commit c9fe5d26b3
2 changed files with 10 additions and 0 deletions

View File

@@ -118,6 +118,11 @@ func (c *grpcExecutorClient) handleStats(ctx context.Context, stream proto.Execu
defer close(ch)
for {
resp, err := stream.Recv()
if ctx.Err() != nil {
// Context canceled; exit gracefully
return
}
if err != nil {
if err != io.EOF {
c.logger.Error("error receiving stream from Stats executor RPC, closing stream", "error", err)

View File

@@ -282,6 +282,11 @@ func (d *driverPluginClient) handleStats(ctx context.Context, ch chan<- *cstruct
defer close(ch)
for {
resp, err := stream.Recv()
if ctx.Err() != nil {
// Context canceled; exit gracefully
return
}
if err != nil {
if err != io.EOF {
d.logger.Error("error receiving stream from TaskStats driver RPC, closing stream", "error", err)