Skip to content

Commit

Permalink
Correctly handle err on Send (#129)
Browse files Browse the repository at this point in the history
* Correct handle err on Send

* feedback
  • Loading branch information
DanG100 authored Sep 7, 2023
1 parent b858e19 commit d36b514
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ygnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ygnmi
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -92,6 +93,13 @@ func subscribe[T any](ctx context.Context, c *Client, q AnyQuery[T], mode gpb.Su
log.V(c.requestLogLevel).Info(prototext.Format(sr))
}
if err := sub.Send(sr); err != nil {
// If the server closes the RPC with an error, the real error may only be visible on Recv.
// https://pkg.go.dev/google.golang.org/grpc?utm_source=godoc#ClientStream
if errors.Is(err, io.EOF) {
if _, recvErr := sub.Recv(); recvErr != nil {
err = recvErr
}
}
return nil, fmt.Errorf("gNMI failed to Send(%+v): %w", sr, err)
}

Expand Down

0 comments on commit d36b514

Please sign in to comment.