pcp
[Top] [All Lists]

libpcp bug fix: multiple connections to same host but different ports

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: libpcp bug fix: multiple connections to same host but different ports
From: "Frank Ch. Eigler" <fche@xxxxxxxxxx>
Date: Fri, 29 Mar 2013 13:18:11 -0400
Delivered-to: pcp@xxxxxxxxxxx
User-agent: Mutt/1.4.2.2i
Hi -

Please consider applying the following patch.


commit 4807819eac0e0c57fb960a1f82edd38cb6625f75
Author: Frank Ch. Eigler <fche@xxxxxxxxxx>
Date:   Fri Mar 29 13:15:20 2013 -0400

    libpcp context.c: Avoid mis-sharing outbound pmcd connections if ports 
mismatch
    
    pmNewContext tries to reuse existing connections to a pmcd, if a
    second context request comes in.  However, for this optimization, it
    only compared host names and not port numbers, which leads to a new
    flavour of false sharing.

diff --git a/src/libpcp/src/context.c b/src/libpcp/src/context.c
index ff05821..023589b 100644
--- a/src/libpcp/src/context.c
+++ b/src/libpcp/src/context.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 Red Hat.
+ * Copyright (c) 2012-2013 Red Hat.
  * Copyright (c) 2007-2008 Aconex.  All Rights Reserved.
  * Copyright (c) 1995-2002,2004,2006,2008 Silicon Graphics, Inc.  All Rights 
Reserved.
  * 
@@ -365,15 +365,23 @@ pmNewContext(int type, const char *name)
            }
        }
 
-       if (nhosts == 1) {
+        /* As an optimization, if there is already a connection to the same 
PMCD,
+           we try to reuse (share) it. */
+       if (nhosts == 1) { /* not proxied */
            for (i = 0; i < contexts_len; i++) {
                if (i == PM_TPD(curcontext))
                    continue;
                if (contexts[i]->c_type == new->c_type &&
                    contexts[i]->c_flags == new->c_flags &&
-                   strcmp(contexts[i]->c_pmcd->pc_hosts[0].name,
-                           hosts[0].name) == 0) {
-                   new->c_pmcd = contexts[i]->c_pmcd;
+                   strcmp(contexts[i]->c_pmcd->pc_hosts[0].name, 
hosts[0].name) == 0 &&
+                    contexts[i]->c_pmcd->pc_hosts[0].nports == 
hosts[0].nports) {
+                    int j;
+                    int ports_same = 1;
+                    for (j=0; j<hosts[0].nports; j++)
+                        if (contexts[i]->c_pmcd->pc_hosts[0].ports[j] != 
hosts[0].ports[j])
+                            ports_same = 0;
+                    if (ports_same)
+                        new->c_pmcd = contexts[i]->c_pmcd;
                }
            }
        }

<Prev in Thread] Current Thread [Next in Thread>
  • libpcp bug fix: multiple connections to same host but different ports, Frank Ch. Eigler <=