Make grpc plugin client use an atomic server value to fix a data race. (#4089)

Also add some coordination to ensure we don't try to clean up the grpc
server before it's created/started
This commit is contained in:
Jeff Mitchell
2018-03-07 09:09:37 -05:00
committed by GitHub
parent b334a3ead7
commit 65bd8dc8b0
2 changed files with 29 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package plugin
import (
"context"
"net/rpc"
"sync/atomic"
"google.golang.org/grpc"
@@ -42,10 +43,17 @@ func (b BackendPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) err
}
func (p *BackendPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &backendGRPCPluginClient{
ret := &backendGRPCPluginClient{
client: pb.NewBackendClient(c),
clientConn: c,
broker: broker,
cleanupCh: make(chan struct{}),
doneCtx: ctx,
}, nil
}
// Create the value and set the type
ret.server = new(atomic.Value)
ret.server.Store((*grpc.Server)(nil))
return ret, nil
}