aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2016-12-12 08:41:42 -0800
committerGravatar Mark D. Roth <roth@google.com>2016-12-12 08:41:42 -0800
commitf75d26925f3371b44b774b15165d79484f3f12e1 (patch)
tree2d22ce1d3b5d8fb7bf13db3747adef367a687248 /src
parentc217e490b176669bf93c04e772218d88b5fef764 (diff)
Fix grpclb code.
Diffstat (limited to 'src')
-rw-r--r--src/core/ext/lb_policy/grpclb/grpclb.c8
-rw-r--r--src/core/ext/transport/chttp2/client/insecure/channel_create.c26
-rw-r--r--src/core/ext/transport/chttp2/client/secure/secure_channel_create.c24
3 files changed, 37 insertions, 21 deletions
diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c
index df0db61c22..da1cf65060 100644
--- a/src/core/ext/lb_policy/grpclb/grpclb.c
+++ b/src/core/ext/lb_policy/grpclb/grpclb.c
@@ -818,9 +818,15 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx,
* We need the LB channel to return addresses with is_balancer=false
* so that it does not wind up recursively using the grpclb LB policy,
* as per the special case logic in client_channel.c.
+ *
+ * Finally, we also strip out the channel arg for the server URI,
+ * since that will be different for the LB channel than for the parent
+ * channel. (The client channel factory will re-add this arg with
+ * the right value.)
*/
static const char *keys_to_remove[] = {GRPC_ARG_LB_POLICY_NAME,
- GRPC_ARG_LB_ADDRESSES};
+ GRPC_ARG_LB_ADDRESSES,
+ GRPC_ARG_SERVER_URI};
grpc_channel_args *new_args = grpc_channel_args_copy_and_remove(
args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove));
glb_policy->lb_channel = grpc_client_channel_factory_create_channel(
diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
index 1e1bed10dc..90d3503959 100644
--- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c
+++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
@@ -65,7 +65,16 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const char *target, grpc_client_channel_type type,
const grpc_channel_args *args) {
- return grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
+ // Add channel arg containing the server URI.
+ grpc_arg arg;
+ arg.type = GRPC_ARG_STRING;
+ arg.key = GRPC_ARG_SERVER_URI;
+ arg.value.string = (char *)target;
+ grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
+ grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
+ GRPC_CLIENT_CHANNEL, NULL);
+ grpc_channel_args_destroy(new_args);
+ return channel;
}
static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
@@ -90,19 +99,14 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
GPR_ASSERT(reserved == NULL);
grpc_client_channel_factory *factory =
(grpc_client_channel_factory *)&client_channel_factory;
- // Add channel args containing the server name and client channel factory.
- grpc_arg new_args[2];
- new_args[0].type = GRPC_ARG_STRING;
- new_args[0].key = GRPC_ARG_SERVER_URI;
- new_args[0].value.string = (char *)target;
- new_args[1] = grpc_client_channel_factory_create_channel_arg(factory);
- grpc_channel_args *args_copy =
- grpc_channel_args_copy_and_add(args, new_args, GPR_ARRAY_SIZE(new_args));
+ // Add channel arg containing the client channel factory.
+ grpc_arg arg = grpc_client_channel_factory_create_channel_arg(factory);
+ grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
// Create channel.
grpc_channel *channel = client_channel_factory_create_channel(
- &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args_copy);
+ &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
// Clean up.
- grpc_channel_args_destroy(args_copy);
+ grpc_channel_args_destroy(new_args);
grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx);
return channel != NULL ? channel : grpc_lame_client_channel_create(
diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
index 2474f544cf..9b6d3819b6 100644
--- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
+++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
@@ -89,7 +89,16 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const char *target, grpc_client_channel_type type,
const grpc_channel_args *args) {
- return grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
+ // Add channel arg containing the server URI.
+ grpc_arg arg;
+ arg.type = GRPC_ARG_STRING;
+ arg.key = GRPC_ARG_SERVER_URI;
+ arg.value.string = (char *)target;
+ grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
+ grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
+ GRPC_CLIENT_CHANNEL, NULL);
+ grpc_channel_args_destroy(new_args);
+ return channel;
}
static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
@@ -137,14 +146,11 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
GRPC_SECURITY_CONNECTOR_REF(&security_connector->base,
"grpc_secure_channel_create");
f->security_connector = security_connector;
- // Add channel args containing the server name, client channel
- // factory, and security connector.
- grpc_arg new_args[3];
- new_args[0].type = GRPC_ARG_STRING;
- new_args[0].key = GRPC_ARG_SERVER_URI;
- new_args[0].value.string = (char *)target;
- new_args[1] = grpc_client_channel_factory_create_channel_arg(&f->base);
- new_args[2] = grpc_security_connector_to_arg(&security_connector->base);
+ // Add channel args containing the client channel factory and security
+ // connector.
+ grpc_arg new_args[2];
+ new_args[0] = grpc_client_channel_factory_create_channel_arg(&f->base);
+ new_args[1] = grpc_security_connector_to_arg(&security_connector->base);
grpc_channel_args *args_copy = grpc_channel_args_copy_and_add(
new_args_from_connector != NULL ? new_args_from_connector : args,
new_args, GPR_ARRAY_SIZE(new_args));