From 3bf828f602247b6af2b7ccd45eb45fc86d67b597 Mon Sep 17 00:00:00 2001
From: Craig Tiller <ctiller@google.com>
Date: Mon, 5 Oct 2015 13:36:25 -0700
Subject: [PATCH] Add a more useful log message when failing to connect

---
 src/core/iomgr/tcp_client_posix.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c
index 346566866a..aca2691c41 100644
--- a/src/core/iomgr/tcp_client_posix.c
+++ b/src/core/iomgr/tcp_client_posix.c
@@ -141,7 +141,8 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, int success) {
       err = getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &so_error, &so_error_size);
     } while (err < 0 && errno == EINTR);
     if (err < 0) {
-      gpr_log(GPR_ERROR, "getsockopt(ERROR): %s", strerror(errno));
+      gpr_log(GPR_ERROR, "failed to connect to '%s': getsockopt(ERROR): %s",
+              ac->addr_str, strerror(errno));
       goto finish;
     } else if (so_error != 0) {
       if (so_error == ENOBUFS) {
@@ -166,10 +167,14 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, int success) {
       } else {
         switch (so_error) {
           case ECONNREFUSED:
-            gpr_log(GPR_ERROR, "socket error: connection refused");
+            gpr_log(
+                GPR_ERROR,
+                "failed to connect to '%s': socket error: connection refused",
+                ac->addr_str);
             break;
           default:
-            gpr_log(GPR_ERROR, "socket error: %d", so_error);
+            gpr_log(GPR_ERROR, "failed to connect to '%s': socket error: %d",
+                    ac->addr_str, so_error);
             break;
         }
         goto finish;
@@ -181,7 +186,8 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, int success) {
       goto finish;
     }
   } else {
-    gpr_log(GPR_ERROR, "on_writable failed during connect");
+    gpr_log(GPR_ERROR, "failed to connect to '%s': timeout occurred",
+            ac->addr_str);
     goto finish;
   }
 
-- 
GitLab