Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8B0BC200D51 for ; Fri, 22 Dec 2017 18:13:30 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 89A6E160C2D; Fri, 22 Dec 2017 17:13:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CFF8A160C0A for ; Fri, 22 Dec 2017 18:13:29 +0100 (CET) Received: (qmail 6015 invoked by uid 500); 22 Dec 2017 17:13:29 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 6005 invoked by uid 99); 22 Dec 2017 17:13:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Dec 2017 17:13:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E854DDFC25; Fri, 22 Dec 2017 17:13:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aconway@apache.org To: commits@qpid.apache.org Date: Fri, 22 Dec 2017 17:13:28 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect archived-at: Fri, 22 Dec 2017 17:13:30 -0000 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 Authored: Thu Dec 21 12:01:07 2017 -0500 Committer: Alan Conway 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