Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-srhodes committed Sep 18, 2023
1 parent 17326b5 commit 7337369
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions proxy/server/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ func (s *TargetStream) Run(nonce uint32, replyChan chan *pb.ProxyReply) {
}
var err error
defer cancel()
s.grpcConn, err = s.dialer.DialContext(dialCtx, s.target, opts...)
grpcConn, err := s.dialer.DialContext(dialCtx, s.target, opts...)
if err != nil {
// We cannot create a new stream to the target. So we need to cancel this stream.
s.logger.Info("unable to create stream", "status", err)
s.cancelFunc()
return err
}
s.grpcConn = grpcConn
grpcStream, err := s.grpcConn.NewStream(s.ctx, s.serviceMethod.StreamDesc(), s.serviceMethod.FullName())
if err != nil {
// We cannot create a new stream to the target. So we need to cancel this stream.
Expand Down Expand Up @@ -325,8 +326,10 @@ func (s *TargetStream) Run(nonce uint32, replyChan chan *pb.ProxyReply) {

// Once all calls are complete, we need to close our network connection
// to the server.
if closeErr := s.grpcConn.Close(); err == nil && closeErr != nil {
err = closeErr
if s.grpcConn != nil {
if closeErr := s.grpcConn.Close(); err == nil && closeErr != nil {
err = closeErr
}
}

// The error status may by set/overidden if CloseWith was used to
Expand Down
8 changes: 6 additions & 2 deletions proxy/server/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// A TargetDialer than returns an error for all Dials
type dialErrTargetDialer codes.Code

func (e dialErrTargetDialer) DialContext(ctx context.Context, target string, dialOpts ...grpc.DialOption) (grpc.ClientConnInterface, error) {
func (e dialErrTargetDialer) DialContext(ctx context.Context, target string, dialOpts ...grpc.DialOption) (ClientConnCloser, error) {
return nil, status.Error(codes.Code(e), "")
}

Expand Down Expand Up @@ -150,10 +150,14 @@ func (b blockingClientConn) NewStream(ctx context.Context, desc *grpc.StreamDesc
return nil, ctx.Err()
}

func (b blockingClientConn) Close() error {
return nil
}

// a context dialer that returns blockingClientConn
type blockingClientDialer struct{}

func (b blockingClientDialer) DialContext(ctx context.Context, target string, dialOpts ...grpc.DialOption) (grpc.ClientConnInterface, error) {
func (b blockingClientDialer) DialContext(ctx context.Context, target string, dialOpts ...grpc.DialOption) (ClientConnCloser, error) {
return blockingClientConn{}, nil
}

Expand Down

0 comments on commit 7337369

Please sign in to comment.