Browse Source

Merge pull request #289 from gravitl/v0.8_optimization

Cleaned up connections
dcarns 3 years ago
parent
commit
914b40a930

+ 2 - 0
netclient/functions/checkin.go

@@ -171,6 +171,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
 		ncutils.PrintLog("Cant dial GRPC server: "+err.Error(), 1)
 		return nil, err
 	}
+	defer conn.Close()
 	wcclient := nodepb.NewNodeServiceClient(conn)
 
 	ctx, err := auth.SetJWT(wcclient, network)
@@ -253,6 +254,7 @@ func Push(network string) error {
 		ncutils.PrintLog("Cant dial GRPC server: "+err.Error(), 1)
 		return err
 	}
+	defer conn.Close()
 	wcclient = nodepb.NewNodeServiceClient(conn)
 
 	ctx, err := auth.SetJWT(wcclient, network)

+ 2 - 1
netclient/functions/common.go

@@ -156,7 +156,7 @@ func Uninstall() error {
 	} else if ncutils.IsMac() {
 		daemon.CleanupMac()
 	} else if !ncutils.IsKernel() {
-		ncutils.PrintLog("manual cleanup required",1)
+		ncutils.PrintLog("manual cleanup required", 1)
 	}
 
 	return err
@@ -177,6 +177,7 @@ func LeaveNetwork(network string) error {
 	if err != nil {
 		log.Printf("Unable to establish client connection to "+servercfg.GRPCAddress+": %v", err)
 	} else {
+		defer conn.Close()
 		wcclient = nodepb.NewNodeServiceClient(conn)
 
 		ctx, err := auth.SetJWT(wcclient, network)

+ 1 - 1
netclient/functions/join.go

@@ -90,7 +90,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
 	if err != nil {
 		log.Fatalf("Unable to establish client connection to "+cfg.Server.GRPCAddress+": %v", err)
 	}
-
+	defer conn.Close()
 	wcclient = nodepb.NewNodeServiceClient(conn)
 
 	postnode := &models.Node{

+ 5 - 2
netclient/server/grpc.go

@@ -29,6 +29,7 @@ func getGrpcClient(cfg *config.ClientConfig) (nodepb.NodeServiceClient, error) {
 	if err != nil {
 		return nil, err
 	}
+	defer conn.Close()
 	wcclient = nodepb.NewNodeServiceClient(conn)
 	return wcclient, nil
 }
@@ -138,6 +139,7 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
 	if err != nil {
 		log.Fatalf("Unable to establish client connection to localhost:50051: %v", err)
 	}
+	defer conn.Close()
 	// Instantiate the BlogServiceClient with our client connection to the server
 	wcclient = nodepb.NewNodeServiceClient(conn)
 
@@ -215,11 +217,11 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
 					continue // if can't parse CIDR
 				}
 				nodeEndpointArr := strings.Split(node.Endpoint, ":") // getting the public ip of node
-				if ipnet.Contains(net.ParseIP(nodeEndpointArr[0])) {         // ensuring egress gateway range does not contain public ip of node
+				if ipnet.Contains(net.ParseIP(nodeEndpointArr[0])) { // ensuring egress gateway range does not contain public ip of node
 					ncutils.PrintLog("egress IP range of "+iprange+" overlaps with "+node.Endpoint+", omitting", 2)
 					continue // skip adding egress range if overlaps with node's ip
 				}
-				if ipnet.Contains(net.ParseIP(nodecfg.LocalAddress)) {         // ensuring egress gateway range does not contain public ip of node
+				if ipnet.Contains(net.ParseIP(nodecfg.LocalAddress)) { // ensuring egress gateway range does not contain public ip of node
 					ncutils.PrintLog("egress IP range of "+iprange+" overlaps with "+nodecfg.LocalAddress+", omitting", 2)
 					continue // skip adding egress range if overlaps with node's local ip
 				}
@@ -293,6 +295,7 @@ func GetExtPeers(macaddress string, network string, server string, dualstack boo
 	if err != nil {
 		log.Fatalf("Unable to establish client connection to localhost:50051: %v", err)
 	}
+	defer conn.Close()
 	// Instantiate the BlogServiceClient with our client connection to the server
 	wcclient = nodepb.NewNodeServiceClient(conn)