You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/12/22 17:13:28 UTC

[1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect

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 <ac...@redhat.com>
Authored: Thu Dec 21 12:01:07 2017 -0500
Committer: Alan Conway <ac...@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


[2/2] qpid-proton git commit: PROTON-1727 [epoll] fix race condition

Posted by ac...@apache.org.
PROTON-1727 [epoll] fix race condition

Needed to set current_arm flag on second and subsequent connect attempts when
resolve returns multiple socket addresses. Otherwise another thread can delete
the connection early.


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

Branch: refs/heads/master
Commit: 223e6d012dab8bbe4bdb92538d84c630bbd1cf27
Parents: 8d91e54
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Dec 22 11:14:05 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 22 12:11:10 2017 -0500

----------------------------------------------------------------------
 proton-c/src/proactor/epoll.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/223e6d01/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index b4f08b7..8f6dacb 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -1096,6 +1096,7 @@ static pn_event_batch_t *pconnection_process(pconnection_t *pc, uint32_t events,
   }
 
   if (pc->new_events) {
+    pc->current_arm = 0;
     if (!pc->context.closing) {
       if ((pc->new_events & (EPOLLHUP | EPOLLERR)) && !pconnection_rclosed(pc) && !pconnection_wclosed(pc))
         pconnection_maybe_connect_lh(pc);
@@ -1106,7 +1107,6 @@ static pn_event_batch_t *pconnection_process(pconnection_t *pc, uint32_t events,
       if (pc->new_events & EPOLLIN)
         pc->read_blocked = false;
     }
-    pc->current_arm = 0;
     pc->new_events = 0;
   }
 
@@ -1227,9 +1227,10 @@ void pconnection_connected_lh(pconnection_t *pc) {
   }
 }
 
+/* multi-address connections may call pconnection_start multiple times with diffferent FDs  */
 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 timer, a no-op if the timer has already started. */
   start_polling(&pc->timer.epoll_io, efd);  // TODO: check for error
 
   /* Get the local socket name now, get the peer name in pconnection_connected */
@@ -1243,7 +1244,7 @@ static void pconnection_start(pconnection_t *pc) {
     pclosefd(pc->psocket.proactor, fd);
   }
   ee->fd = pc->psocket.sockfd;
-  ee->wanted = EPOLLIN | EPOLLOUT;
+  pc->current_arm = ee->wanted = EPOLLIN | EPOLLOUT;
   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


Re: dispatch tests failing (Re: [1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect)

Posted by Robbie Gemmell <ro...@gmail.com>.
Showing the same on TravisCI, e.g:
https://travis-ci.org/apache/qpid-dispatch/builds/324311983

On 10 January 2018 at 10:19, Gordon Sim <gs...@redhat.com> wrote:
> I see two if the dispatch system tests failing after the following commit to
> proton (they all when run against a proton lib before this patch).
> Subsequent commits to proton don't help either - dispatch tests fail against
> latest proton master also.
>
> The tests that fail are system_tests_user_id_proxy and system_tests_policy.
>
> On 22/12/17 17:13, aconway@apache.org wrote:
>>
>> 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 <ac...@redhat.com>
>> Authored: Thu Dec 21 12:01:07 2017 -0500
>> Committer: Alan Conway <ac...@redhat.com>
>> Committed: Fri Dec 22 12:11:08 2017 -0500
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
> For additional commands, e-mail: dev-help@qpid.apache.org
>

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


Re: dispatch tests failing (Re: [1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect)

Posted by Gordon Sim <gs...@redhat.com>.
On 12/01/18 21:54, Gordon Sim wrote:
> On 10/01/18 10:19, Gordon Sim wrote:
>> I see two if the dispatch system tests failing after the following 
>> commit to proton (they all when run against a proton lib before this 
>> patch). Subsequent commits to proton don't help either - dispatch 
>> tests fail against latest proton master also.
>>
>> The tests that fail are system_tests_user_id_proxy and 
>> system_tests_policy.
> 
> The problem I believe is that this change moves the retrieval of the 
> remote address from pconnection_start to pconnection_connected_lh and 
> this means that when the router tries to get the hostname for the 
> connection (to do policy checks) in the connection_bound event, it 
> hasn't yet been retrieved.
> 
> I don't really understand the issue this change is trying to fix, so not 
> sure how best to address the issue yet. Any ideas?

Fyi: I committed a fix for this (see DISPATCH-912 if interested).


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


Re: dispatch tests failing (Re: [1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect)

Posted by Gordon Sim <gs...@redhat.com>.
On 10/01/18 10:19, Gordon Sim wrote:
> I see two if the dispatch system tests failing after the following 
> commit to proton (they all when run against a proton lib before this 
> patch). Subsequent commits to proton don't help either - dispatch tests 
> fail against latest proton master also.
> 
> The tests that fail are system_tests_user_id_proxy and system_tests_policy.

The problem I believe is that this change moves the retrieval of the 
remote address from pconnection_start to pconnection_connected_lh and 
this means that when the router tries to get the hostname for the 
connection (to do policy checks) in the connection_bound event, it 
hasn't yet been retrieved.

I don't really understand the issue this change is trying to fix, so not 
sure how best to address the issue yet. Any ideas?

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


dispatch tests failing (Re: [1/2] qpid-proton git commit: PROTON-1727 [epoll] fix file descriptor leak on reconnect)

Posted by Gordon Sim <gs...@redhat.com>.
I see two if the dispatch system tests failing after the following 
commit to proton (they all when run against a proton lib before this 
patch). Subsequent commits to proton don't help either - dispatch tests 
fail against latest proton master also.

The tests that fail are system_tests_user_id_proxy and system_tests_policy.

On 22/12/17 17:13, aconway@apache.org wrote:
> 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 <ac...@redhat.com>
> Authored: Thu Dec 21 12:01:07 2017 -0500
> Committer: Alan Conway <ac...@redhat.com>
> Committed: Fri Dec 22 12:11:08 2017 -0500


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