diff --git a/drivers/shared/executor/client.go b/drivers/shared/executor/client.go index 1e44788f6..101583605 100644 --- a/drivers/shared/executor/client.go +++ b/drivers/shared/executor/client.go @@ -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) diff --git a/plugins/drivers/client.go b/plugins/drivers/client.go index 8a2e828e7..11babf249 100644 --- a/plugins/drivers/client.go +++ b/plugins/drivers/client.go @@ -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)