diff --git a/src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.c b/src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.c index 3d5eab0b4eb..9251b3d708b 100644 --- a/src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.c +++ b/src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.c @@ -242,11 +242,12 @@ void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name, grpc_ares_request *r = NULL; grpc_ares_ev_driver *ev_driver; - if ((err = grpc_customized_resolve_address(name, default_port, addrs)) != - GRPC_ERROR_CANCELLED) { + if (grpc_customized_resolve_address(name, default_port, addrs, &err) != 0) { grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL); return; } + GRPC_ERROR_UNREF(err); + err = GRPC_ERROR_NONE; /* parse name, splitting it into host and port parts */ gpr_split_host_port(name, &host, &port); diff --git a/src/core/lib/iomgr/resolve_address.h b/src/core/lib/iomgr/resolve_address.h index 7a770662ccf..a3a256eb529 100644 --- a/src/core/lib/iomgr/resolve_address.h +++ b/src/core/lib/iomgr/resolve_address.h @@ -66,11 +66,11 @@ extern grpc_error *(*grpc_blocking_resolve_address)( const char *name, const char *default_port, grpc_resolved_addresses **addresses); -/* Returns GRPC_ERROR_CANCELLED by default. If it's overriden and returns - error other than GRPC_ERROR_CANCELLED, grpc_resolve_address will use its - result. Result must be freed with grpc_resolved_addresses_destroy. */ -extern grpc_error *(*grpc_customized_resolve_address)( +/* Returns 0 by default. If it's overriden and returns value other than 0, + grpc_resolve_address will use its result. Result must be freed with + grpc_resolved_addresses_destroy. */ +extern int (*grpc_customized_resolve_address)( const char *name, const char *default_port, - grpc_resolved_addresses **addresses); + grpc_resolved_addresses **addresses, grpc_error **error); #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */ diff --git a/src/core/lib/iomgr/resolve_address_posix.c b/src/core/lib/iomgr/resolve_address_posix.c index 4012dcc61ff..4010c008b4e 100644 --- a/src/core/lib/iomgr/resolve_address_posix.c +++ b/src/core/lib/iomgr/resolve_address_posix.c @@ -149,16 +149,17 @@ grpc_error *(*grpc_blocking_resolve_address)( const char *name, const char *default_port, grpc_resolved_addresses **addresses) = blocking_resolve_address_impl; -static grpc_error *default_customized_resolve_address_impl( +static int default_customized_resolve_address_impl( const char *name, const char *default_port, - grpc_resolved_addresses **addresses) { - return GRPC_ERROR_CANCELLED; + grpc_resolved_addresses **addresses, grpc_error **error) { + *error = GRPC_ERROR_NONE; + return 0; } -grpc_error *(*grpc_customized_resolve_address)( +int (*grpc_customized_resolve_address)( const char *name, const char *default_port, - grpc_resolved_addresses **addresses) = - default_customized_resolve_address_impl; + grpc_resolved_addresses **addresses, + grpc_error **error) = default_customized_resolve_address_impl; typedef struct { char *name; @@ -197,8 +198,7 @@ static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name, request *r; grpc_error *err; - if ((err = grpc_customized_resolve_address(name, default_port, addrs)) != - GRPC_ERROR_CANCELLED) { + if (grpc_customized_resolve_address(name, default_port, addrs, &err) != 0) { grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL); return; } diff --git a/src/core/lib/iomgr/resolve_address_windows.c b/src/core/lib/iomgr/resolve_address_windows.c index f7f331aa943..1c8f077698b 100644 --- a/src/core/lib/iomgr/resolve_address_windows.c +++ b/src/core/lib/iomgr/resolve_address_windows.c @@ -143,16 +143,18 @@ grpc_error *(*grpc_blocking_resolve_address)( const char *name, const char *default_port, grpc_resolved_addresses **addresses) = blocking_resolve_address_impl; -static grpc_error *default_customized_resolve_address_impl( +static int default_customized_resolve_address_impl( const char *name, const char *default_port, - grpc_resolved_addresses **addresses) { - return GRPC_ERROR_CANCELLED; + grpc_resolved_addresses **addresses, grpc_error **error) { + *addresses = NULL; + *error = GRPC_ERROR_CANCELLED; + return 0; } -grpc_error *(*grpc_customized_resolve_address)( +int (*grpc_customized_resolve_address)( const char *name, const char *default_port, - grpc_resolved_addresses **addresses) = - default_customized_resolve_address_impl; + grpc_resolved_addresses **addresses, + grpc_error **error) = default_customized_resolve_address_impl; /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ @@ -185,8 +187,8 @@ static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name, request *r; grpc_error *err; - if ((err = grpc_customized_resolve_address(name, default_port, addresses)) != - GRPC_ERROR_CANCELLED) { + if (grpc_customized_resolve_address(name, default_port, addresses, &err) != + 0) { grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL); return; } diff --git a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c b/test/core/client_config/resolvers/dns_resolver_connectivity_test.c index 6002b0b7bb7..f6349527cb7 100644 --- a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c +++ b/test/core/client_config/resolvers/dns_resolver_connectivity_test.c @@ -67,22 +67,24 @@ static grpc_client_channel_factory cc_factory = {&sc_vtable}; static gpr_mu g_mu; static bool g_fail_resolution = true; -static grpc_error *my_resolve_address(const char *name, const char *addr, - grpc_resolved_addresses **addrs) { +static int my_resolve_address(const char *name, const char *addr, + grpc_resolved_addresses **addrs, + grpc_error **error) { gpr_mu_lock(&g_mu); GPR_ASSERT(0 == strcmp("test", name)); if (g_fail_resolution) { g_fail_resolution = false; gpr_mu_unlock(&g_mu); - return GRPC_ERROR_CREATE("Forced Failure"); + *error = GRPC_ERROR_CREATE("Forced Failure"); } else { gpr_mu_unlock(&g_mu); *addrs = gpr_malloc(sizeof(**addrs)); (*addrs)->naddrs = 1; (*addrs)->addrs = gpr_malloc(sizeof(*(*addrs)->addrs)); (*addrs)->addrs[0].len = 123; - return GRPC_ERROR_NONE; + *error = GRPC_ERROR_NONE; } + return 1; } static grpc_resolver *create_resolver(const char *name) { diff --git a/test/core/end2end/goaway_server_test.c b/test/core/end2end/goaway_server_test.c index ed8cc3dd68e..d1cb4fe3cbf 100644 --- a/test/core/end2end/goaway_server_test.c +++ b/test/core/end2end/goaway_server_test.c @@ -53,16 +53,17 @@ static void set_resolve_port(int port) { gpr_mu_unlock(&g_mu); } -static grpc_error *my_resolve_address(const char *name, const char *addr, - grpc_resolved_addresses **addrs) { +static int my_resolve_address(const char *name, const char *addr, + grpc_resolved_addresses **addrs, + grpc_error **error) { if (0 != strcmp(name, "test")) { - return GRPC_ERROR_CANCELLED; + return 0; } gpr_mu_lock(&g_mu); if (g_resolve_port < 0) { gpr_mu_unlock(&g_mu); - return GRPC_ERROR_CREATE("Forced Failure"); + *error = GRPC_ERROR_CREATE("Forced Failure"); } else { *addrs = gpr_malloc(sizeof(**addrs)); (*addrs)->naddrs = 1; @@ -74,8 +75,9 @@ static grpc_error *my_resolve_address(const char *name, const char *addr, sa->sin_port = htons((uint16_t)g_resolve_port); (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); - return GRPC_ERROR_NONE; + *error = GRPC_ERROR_NONE; } + return 1; } int main(int argc, char **argv) {