소스 검색

Merge pull request #9525 from murgatroid99/uv_tcp_connection_fix

Fix bugs in UV DNS resolver implementation
Michael Lumish 8 년 전
부모
커밋
693a910e57
2개의 변경된 파일17개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 2
      src/core/lib/iomgr/resolve_address_uv.c
  2. 14 0
      src/core/lib/iomgr/tcp_client_uv.c

+ 3 - 2
src/core/lib/iomgr/resolve_address_uv.c

@@ -113,14 +113,15 @@ static grpc_error *try_split_host_port(const char *name,
   /* parse name, splitting it into host and port parts */
   /* parse name, splitting it into host and port parts */
   grpc_error *error;
   grpc_error *error;
   gpr_split_host_port(name, host, port);
   gpr_split_host_port(name, host, port);
-  if (host == NULL) {
+  if (*host == NULL) {
     char *msg;
     char *msg;
     gpr_asprintf(&msg, "unparseable host:port: '%s'", name);
     gpr_asprintf(&msg, "unparseable host:port: '%s'", name);
     error = GRPC_ERROR_CREATE(msg);
     error = GRPC_ERROR_CREATE(msg);
     gpr_free(msg);
     gpr_free(msg);
     return error;
     return error;
   }
   }
-  if (port == NULL) {
+  if (*port == NULL) {
+    // TODO(murgatroid99): add tests for this case
     if (default_port == NULL) {
     if (default_port == NULL) {
       char *msg;
       char *msg;
       gpr_asprintf(&msg, "no port in name '%s'", name);
       gpr_asprintf(&msg, "no port in name '%s'", name);

+ 14 - 0
src/core/lib/iomgr/tcp_client_uv.c

@@ -46,6 +46,8 @@
 #include "src/core/lib/iomgr/tcp_uv.h"
 #include "src/core/lib/iomgr/tcp_uv.h"
 #include "src/core/lib/iomgr/timer.h"
 #include "src/core/lib/iomgr/timer.h"
 
 
+extern int grpc_tcp_trace;
+
 typedef struct grpc_uv_tcp_connect {
 typedef struct grpc_uv_tcp_connect {
   uv_connect_t connect_req;
   uv_connect_t connect_req;
   grpc_timer alarm;
   grpc_timer alarm;
@@ -70,6 +72,12 @@ static void uv_tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp,
                            grpc_error *error) {
                            grpc_error *error) {
   int done;
   int done;
   grpc_uv_tcp_connect *connect = acp;
   grpc_uv_tcp_connect *connect = acp;
+  if (grpc_tcp_trace) {
+    const char *str = grpc_error_string(error);
+    gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s",
+            connect->addr_name, str);
+    grpc_error_free_string(str);
+  }
   if (error == GRPC_ERROR_NONE) {
   if (error == GRPC_ERROR_NONE) {
     /* error == NONE implies that the timer ran out, and wasn't cancelled. If
     /* error == NONE implies that the timer ran out, and wasn't cancelled. If
        it was cancelled, then the handler that cancelled it also should close
        it was cancelled, then the handler that cancelled it also should close
@@ -145,6 +153,12 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx,
   connect->resource_quota = resource_quota;
   connect->resource_quota = resource_quota;
   uv_tcp_init(uv_default_loop(), connect->tcp_handle);
   uv_tcp_init(uv_default_loop(), connect->tcp_handle);
   connect->connect_req.data = connect;
   connect->connect_req.data = connect;
+
+  if (grpc_tcp_trace) {
+    gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting",
+            connect->addr_name);
+  }
+
   // TODO(murgatroid99): figure out what the return value here means
   // TODO(murgatroid99): figure out what the return value here means
   uv_tcp_connect(&connect->connect_req, connect->tcp_handle,
   uv_tcp_connect(&connect->connect_req, connect->tcp_handle,
                  (const struct sockaddr *)resolved_addr->addr,
                  (const struct sockaddr *)resolved_addr->addr,