qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect
Date Fri, 22 Dec 2017 17:13:28 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master b462433e3 -> 223e6d012


PROTON-1727 [epoll] fix file descriptor leak on reconnect

Fix a file descriptor leak when a host name resolves to multiple socket
addresses and connecting to the first address fails.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/8d91e54c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/8d91e54c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/8d91e54c

Branch: refs/heads/master
Commit: 8d91e54c4445f8f7fcac44150de5ee2da34a3571
Parents: b462433
Author: Alan Conway <aconway@redhat.com>
Authored: Thu Dec 21 12:01:07 2017 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Fri Dec 22 12:11:08 2017 -0500

----------------------------------------------------------------------
 proton-c/src/proactor/epoll.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8d91e54c/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index 84986f2..b4f08b7 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -762,6 +762,8 @@ static void pconnection_tick(pconnection_t *pc);
 
 static const char *pconnection_setup(pconnection_t *pc, pn_proactor_t *p, pn_connection_t
*c, pn_transport_t *t, bool server, const char *addr)
 {
+  memset(pc, 0, sizeof(*pc));
+
   if (pn_connection_driver_init(&pc->driver, c, t) != 0) {
     free(pc);
     return "pn_connection_driver_init failure";
@@ -1220,24 +1222,28 @@ void pconnection_connected_lh(pconnection_t *pc) {
       pc->addrinfo = NULL;
     }
     pc->ai = NULL;
+    socklen_t len = sizeof(pc->remote.ss);
+    (void)getpeername(pc->psocket.sockfd, (struct sockaddr*)&pc->remote.ss, &len);
   }
 }
 
 static void pconnection_start(pconnection_t *pc) {
   int efd = pc->psocket.proactor->epollfd;
+  /* Start polling is a no-op if the timer has alread started. */
   start_polling(&pc->timer.epoll_io, efd);  // TODO: check for error
 
-  int fd = pc->psocket.sockfd;
+  /* Get the local socket name now, get the peer name in pconnection_connected */
   socklen_t len = sizeof(pc->local.ss);
-  (void)getsockname(fd, (struct sockaddr*)&pc->local.ss, &len);
-  len = sizeof(pc->remote.ss);
-  (void)getpeername(fd, (struct sockaddr*)&pc->remote.ss, &len); /* Ignore error,
leave ss null */
+  (void)getsockname(pc->psocket.sockfd, (struct sockaddr*)&pc->local.ss, &len);
 
-  start_polling(&pc->timer.epoll_io, efd);  // TODO: check for error
   epoll_extended_t *ee = &pc->psocket.epoll_io;
+  if (ee->polling) {     /* This is not the first attempt, stop polling and close the
old FD */
+    int fd = ee->fd;     /* Save fd, it will be set to -1 by stop_polling */
+    stop_polling(ee, efd);
+    pclosefd(pc->psocket.proactor, fd);
+  }
   ee->fd = pc->psocket.sockfd;
   ee->wanted = EPOLLIN | EPOLLOUT;
-  ee->polling = false;
   start_polling(ee, efd);  // TODO: check for error
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message