Fixed connections leak in pool on errors.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 4 Nov 2008 16:26:48 +0000 (16:26 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 4 Nov 2008 16:26:48 +0000 (16:26 +0000)
Globus & threads in user_jobs threaded example.
Slight API modification of the internal client function.

org.glite.lb.client/examples/user_jobs_threaded.c
org.glite.lb.client/interface/connection.h
org.glite.lb.client/src/connection.c
org.glite.lb.client/src/prod_proto.c

index fbe0f71..904bfbb 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "glite/lb/context.h"
 #include "glite/lb/xml_conversions.h"
+#include "glite/security/glite_gss.h"
 #include "consumer.h"
 
 int use_proxy = 0;
@@ -175,6 +176,12 @@ int main(int argc,char **argv)
 
         arguments.argv_0 = argv[0];
 
+       /* threads && Globus */
+       if (edg_wll_gss_initialize()) {
+               printf("can't initialize GSS\n");
+               return 1;
+       }
+
        /* Do a thready work */
        {
                pthread_t threads[thr_num];
index 29350e3..f8eca35 100644 (file)
@@ -16,7 +16,7 @@ int http_check_status(edg_wll_Context, char *);
 int ConnectionIndex(edg_wll_Context ctx, const char *name, int port);
 int AddConnection(edg_wll_Context ctx, char *name, int port);
 int ReleaseConnection(edg_wll_Context ctx, char *name, int port);
-int CloseConnection(edg_wll_Context ctx, int* conn_index);
+int CloseConnection(edg_wll_Context ctx, int conn_index);
 
 #define PROXY_CONNECT_RETRY 10 /* ms */
 
index a066ae4..ad5c168 100644 (file)
 #include "connection.h"
 
 
-int CloseConnection(edg_wll_Context ctx, int* conn_index)
-// XXX: should change the parameter conn_index to int (parameter is IN only)
+int CloseConnection(edg_wll_Context ctx, int conn_index)
 {
        /* close connection and free its structures */
        int cIndex,ret = 0;
 
-        cIndex = *conn_index;
+        cIndex = conn_index;
 
        assert(ctx->connections->connOpened);
 
@@ -46,8 +45,6 @@ int CloseConnection(edg_wll_Context ctx, int* conn_index)
        
        ctx->connections->connOpened--;
 
-// XXX: not needed        *conn_index = cIndex;
-
        return ret;
 }
 
@@ -140,7 +137,7 @@ int ReleaseConnection(edg_wll_Context ctx, char *name, int port)
        
        if (name) {
                if ((index = ConnectionIndex(ctx, name, port)) >= 0)
-                       CloseConnection(ctx, &index);
+                       CloseConnection(ctx, index);
        }
        else {                                  /* free the oldest (unlocked) connection */
                for (i=0; i<ctx->connections->poolSize; i++) {
@@ -162,7 +159,7 @@ int ReleaseConnection(edg_wll_Context ctx, char *name, int port)
                        }
                }
                if (!foundConnToDrop) return edg_wll_SetError(ctx,EAGAIN,"all connections in the connection pool are locked");
-               CloseConnection(ctx, &index);
+               CloseConnection(ctx, index);
        }
        return edg_wll_Error(ctx,NULL,NULL);
 }
@@ -174,7 +171,7 @@ int edg_wll_close(edg_wll_Context ctx, int* connToUse)
        edg_wll_ResetError(ctx);
        if (*connToUse == -1) return 0;
 
-       CloseConnection(ctx, connToUse);
+       CloseConnection(ctx, *connToUse);
 
         edg_wll_connectionUnlock(ctx, *connToUse); /* Forgetting the conn. Unlocking is safe. */
                
@@ -328,7 +325,10 @@ int edg_wll_open(edg_wll_Context ctx, int* connToUse)
 err:
        /* some error occured; close created connection
         * and free all fields in connPool[index] */
-       if (index >= 0) CloseConnection(ctx, &index);
+       if (index >= 0) {
+               CloseConnection(ctx, index);
+               edg_wll_connectionUnlock(ctx, index);
+       }
        *connToUse = -1;
 ok:    
 
index d161d7c..90f6785 100644 (file)
@@ -315,7 +315,10 @@ int edg_wll_log_connect(edg_wll_Context ctx, int *conn)
        } else goto edg_wll_log_connect_end;
 
 edg_wll_log_connect_err:
-       if (index >= 0) CloseConnection(ctx, &index);
+       if (index >= 0) {
+               CloseConnection(ctx, index);
+               edg_wll_connectionUnlock(ctx, index);
+       }
        index = -1;
 
 edg_wll_log_connect_end:
@@ -346,7 +349,7 @@ int edg_wll_log_close(edg_wll_Context ctx, int conn)
        int ret = 0;
 
        if (conn == -1) return 0;
-       ret = CloseConnection(ctx,&conn);
+       ret = CloseConnection(ctx,conn);
        edg_wll_connectionUnlock(ctx,conn);
        return ret;
 }