trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [6/7] trafficserver git commit: TS-3796: health check fails once during startup
Date Mon, 03 Aug 2015 23:10:17 GMT
TS-3796: health check fails once during startup

Make sure that we initialize the socket length so that
accept(2) doesn't spuriously fail.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/35c5a457
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/35c5a457
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/35c5a457

Branch: refs/heads/6.0.x
Commit: 35c5a457c6c154be53cf5907997374ebbe5a990e
Parents: 7abadb7
Author: James Peach <jpeach@apache.org>
Authored: Mon Aug 3 13:34:08 2015 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Mon Aug 3 13:35:46 2015 -0700

----------------------------------------------------------------------
 cmd/traffic_manager/MgmtHandlers.cc | 12 +++++++-----
 mgmt/LocalManager.cc                |  4 ++--
 mgmt/api/EventControlMain.cc        |  2 +-
 mgmt/api/TSControlMain.cc           |  2 +-
 mgmt/cluster/ClusterCom.cc          |  2 +-
 mgmt/utils/MgmtSocket.cc            |  4 +++-
 mgmt/utils/MgmtSocket.h             |  2 +-
 7 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/cmd/traffic_manager/MgmtHandlers.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_manager/MgmtHandlers.cc b/cmd/traffic_manager/MgmtHandlers.cc
index 5e974ef..913037d 100644
--- a/cmd/traffic_manager/MgmtHandlers.cc
+++ b/cmd/traffic_manager/MgmtHandlers.cc
@@ -211,11 +211,9 @@ error:
 void *
 mgmt_synthetic_main(void *)
 {
-  int autoconfFD = -1;           // FD for incoming autoconf connections
-  int clientFD = -1;             // FD for accepted connections
-  int publicPort = -1;           // Port for incoming autoconf connections
-  struct sockaddr_in clientInfo; // Info about client connection
-  int addrLen;
+  int autoconfFD = -1; // FD for incoming autoconf connections
+  int clientFD = -1;   // FD for accepted connections
+  int publicPort = -1; // Port for incoming autoconf connections
 
 #if !defined(linux)
   sigset_t allSigs; // Set of all signals
@@ -245,6 +243,10 @@ mgmt_synthetic_main(void *)
   }
 
   while (1) {
+    struct sockaddr_in clientInfo; // Info about client connection
+    socklen_t addrLen = sizeof(clientInfo);
+
+    ink_zero(clientInfo);
     if ((clientFD = mgmt_accept(autoconfFD, (sockaddr *)&clientInfo, &addrLen)) <
0) {
       mgmt_log(stderr, "[SyntheticHealthServer] accept() on incoming port failed: %s\n",
strerror(errno));
     } else if (safe_setsockopt(clientFD, IPPROTO_TCP, TCP_NODELAY, SOCKOPT_ON, sizeof(int))
< 0) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/mgmt/LocalManager.cc
----------------------------------------------------------------------
diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
index 4630969..30f8cac 100644
--- a/mgmt/LocalManager.cc
+++ b/mgmt/LocalManager.cc
@@ -392,7 +392,6 @@ LocalManager::pollMgmtProcessServer()
 {
   int num;
   struct timeval timeout;
-  struct sockaddr_in clientAddr;
   fd_set fdlist;
 #if TS_HAS_WCCP
   int wccp_fd = wccp_cache.getSocket();
@@ -430,7 +429,8 @@ LocalManager::pollMgmtProcessServer()
       }
 #endif
       if (FD_ISSET(process_server_sockfd, &fdlist)) { /* New connection */
-        int clientLen = sizeof(clientAddr);
+        struct sockaddr_in clientAddr;
+        socklen_t clientLen = sizeof(clientAddr);
         int new_sockfd = mgmt_accept(process_server_sockfd, (struct sockaddr *)&clientAddr,
&clientLen);
         MgmtMessageHdr *mh;
         int data_len;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/mgmt/api/EventControlMain.cc
----------------------------------------------------------------------
diff --git a/mgmt/api/EventControlMain.cc b/mgmt/api/EventControlMain.cc
index c26855f..44ad69c 100644
--- a/mgmt/api/EventControlMain.cc
+++ b/mgmt/api/EventControlMain.cc
@@ -269,7 +269,6 @@ event_callback_main(void *arg)
   InkHashTableIteratorState con_state; // used to iterate through hash table
   int fds_ready;                       // return value for select go here
   struct timeval timeout;
-  int addr_len = (sizeof(struct sockaddr));
 
   while (1) {
     // LINUX fix: to prevent hard-spin reset timeout on each loop
@@ -312,6 +311,7 @@ event_callback_main(void *arg)
           // Debug ("TS_Control_Main", "can't create new EventClientT for new connection\n");
         } else {
           // accept connection
+          socklen_t addr_len = (sizeof(struct sockaddr));
           new_con_fd = mgmt_accept(con_socket_fd, new_client_con->adr, &addr_len);
           new_client_con->fd = new_con_fd;
           ink_hash_table_insert(accepted_clients, (char *)&new_client_con->fd, new_client_con);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/mgmt/api/TSControlMain.cc
----------------------------------------------------------------------
diff --git a/mgmt/api/TSControlMain.cc b/mgmt/api/TSControlMain.cc
index 296b7d5..0673b29 100644
--- a/mgmt/api/TSControlMain.cc
+++ b/mgmt/api/TSControlMain.cc
@@ -139,7 +139,6 @@ ts_ctrl_main(void *arg)
   InkHashTableIteratorState con_state; // used to iterate through hash table
   int fds_ready;                       // stores return value for select
   struct timeval timeout;
-  int addr_len = (sizeof(struct sockaddr));
 
   // loops until TM dies; waits for and processes requests from clients
   while (1) {
@@ -181,6 +180,7 @@ ts_ctrl_main(void *arg)
           // return TS_ERR_SYS_CALL; WHAT TO DO? just keep going
           Debug("ts_main", "[ts_ctrl_main] can't allocate new ClientT\n");
         } else { // accept connection
+          socklen_t addr_len = (sizeof(struct sockaddr));
           new_con_fd = mgmt_accept(con_socket_fd, new_client_con->adr, &addr_len);
           new_client_con->fd = new_con_fd;
           ink_hash_table_insert(accepted_con, (char *)&new_client_con->fd, new_client_con);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/mgmt/cluster/ClusterCom.cc
----------------------------------------------------------------------
diff --git a/mgmt/cluster/ClusterCom.cc b/mgmt/cluster/ClusterCom.cc
index 45055ff..0c8d2ca 100644
--- a/mgmt/cluster/ClusterCom.cc
+++ b/mgmt/cluster/ClusterCom.cc
@@ -167,7 +167,7 @@ drainIncomingChannel(void *arg)
 
     if (mgmt_read_timeout(ccom->reliable_server_fd, ccom->mc_poll_timeout /* secs */,
0 /* usecs */) > 0) {
       /* Reliable(TCP) request */
-      int clilen = sizeof(cli_addr);
+      socklen_t clilen = sizeof(cli_addr);
       int req_fd = mgmt_accept(ccom->reliable_server_fd, (struct sockaddr *)&cli_addr,
&clilen);
       if (req_fd < 0) {
         mgmt_elog(stderr, errno, "[drainIncomingChannel] error accepting "

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/mgmt/utils/MgmtSocket.cc
----------------------------------------------------------------------
diff --git a/mgmt/utils/MgmtSocket.cc b/mgmt/utils/MgmtSocket.cc
index bab4e90..65ae0f4 100644
--- a/mgmt/utils/MgmtSocket.cc
+++ b/mgmt/utils/MgmtSocket.cc
@@ -22,6 +22,7 @@
  */
 
 #include "ts/ink_platform.h"
+#include "ts/ink_assert.h"
 #include "MgmtSocket.h"
 
 #if HAVE_UCRED_H
@@ -61,9 +62,10 @@ mgmt_transient_error()
 //-------------------------------------------------------------------------
 
 int
-mgmt_accept(int s, struct sockaddr *addr, int *addrlen)
+mgmt_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 {
   int r, retries;
+  ink_assert(*addrlen != 0);
   for (retries = 0; retries < MGMT_MAX_TRANSIENT_ERRORS; retries++) {
     r = ::accept(s, addr, (socklen_t *)addrlen);
     if (r >= 0)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/35c5a457/mgmt/utils/MgmtSocket.h
----------------------------------------------------------------------
diff --git a/mgmt/utils/MgmtSocket.h b/mgmt/utils/MgmtSocket.h
index a48228a..eaac8be 100644
--- a/mgmt/utils/MgmtSocket.h
+++ b/mgmt/utils/MgmtSocket.h
@@ -46,7 +46,7 @@ bool mgmt_transient_error();
 // mgmt_accept
 //-------------------------------------------------------------------------
 
-int mgmt_accept(int s, struct sockaddr *addr, int *addrlen);
+int mgmt_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 
 //-------------------------------------------------------------------------
 // mgmt_fopen


Mime
View raw message