mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user