Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring changes from base. #2

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net"
"sync"

log "github.com/golang/glog"
"github.com/Workiva/go-datastructures/queue"
log "github.com/golang/glog"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"

Expand Down Expand Up @@ -118,19 +118,18 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
}
var dc sdc.Client

if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if isTargetDb(target) == true {
dc, err = sdc.NewDbClient(paths, prefix)
} else {
/* For any other target or no target create new Transl Client. */
dc, err = sdc.NewTranslClient(prefix, paths)
}

if err != nil {
return grpc.Errorf(codes.NotFound, "%v", err)
}
if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if isTargetDb(target) == true {
dc, err = sdc.NewDbClient(paths, prefix)
} else {
/* For any other target or no target create new Transl Client. */
dc, err = sdc.NewTranslClient(prefix, paths)
}

if err != nil {
return grpc.Errorf(codes.NotFound, "%v", err)
}

switch mode := c.subscribe.GetMode(); mode {
case gnmipb.SubscriptionList_STREAM:
Expand Down Expand Up @@ -198,6 +197,15 @@ func (c *Client) recv(stream gnmipb.GNMI_SubscribeServer) {
return
case io.EOF:
log.V(1).Infof("Client %s received io.EOF", c)
if c.subscribe.Mode == gnmipb.SubscriptionList_STREAM {
// The client->server could be closed after the sending the subscription list.
// EOF is not a indication of client is not listening.
// Instead stream.Context() which is signaled once the underlying connection is terminated.
log.V(1).Infof("Waiting for client '%s'", c)
// This context is done when the client connection is terminated.
<-stream.Context().Done()
log.V(1).Infof("Client is done '%s'", c)
}
return
case nil:
}
Expand Down