From 796d8636f6f4bda52674ffd09a211546d5ac3f42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 4 Nov 2008 16:26:48 +0000 Subject: [PATCH] Fixed connections leak in pool on errors. Globus & threads in user_jobs threaded example. Slight API modification of the internal client function. --- org.glite.lb.client/examples/user_jobs_threaded.c | 7 +++++++ org.glite.lb.client/interface/connection.h | 2 +- org.glite.lb.client/src/connection.c | 18 +++++++++--------- org.glite.lb.client/src/prod_proto.c | 7 +++++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/org.glite.lb.client/examples/user_jobs_threaded.c b/org.glite.lb.client/examples/user_jobs_threaded.c index fbe0f71..904bfbb 100644 --- a/org.glite.lb.client/examples/user_jobs_threaded.c +++ b/org.glite.lb.client/examples/user_jobs_threaded.c @@ -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]; diff --git a/org.glite.lb.client/interface/connection.h b/org.glite.lb.client/interface/connection.h index 29350e3..f8eca35 100644 --- a/org.glite.lb.client/interface/connection.h +++ b/org.glite.lb.client/interface/connection.h @@ -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 */ diff --git a/org.glite.lb.client/src/connection.c b/org.glite.lb.client/src/connection.c index a066ae4..ad5c168 100644 --- a/org.glite.lb.client/src/connection.c +++ b/org.glite.lb.client/src/connection.c @@ -23,13 +23,12 @@ #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; iconnections->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: diff --git a/org.glite.lb.client/src/prod_proto.c b/org.glite.lb.client/src/prod_proto.c index d161d7c..90f6785 100644 --- a/org.glite.lb.client/src/prod_proto.c +++ b/org.glite.lb.client/src/prod_proto.c @@ -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; } -- 1.8.2.3