From: Aleš Křenek Date: Mon, 14 Aug 2006 13:54:57 +0000 (+0000) Subject: fixes for bug #18994 X-Git-Tag: glite-lb-client_R_2_1_5~2 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=2362b3731b9ffe9c2a40e380df78f090622f07dc;p=jra1mw.git fixes for bug #18994 --- diff --git a/org.glite.lb.client/examples/flood_proxy.c b/org.glite.lb.client/examples/flood_proxy.c index 91c7f8a..f59e426 100644 --- a/org.glite.lb.client/examples/flood_proxy.c +++ b/org.glite.lb.client/examples/flood_proxy.c @@ -14,7 +14,7 @@ static void slave(); int main(int argc,char **argv) { - int i,njobs,nproc; + int i,nproc; if (argc != 2) { fprintf(stderr,"usage: %s nproc\n",argv[0]); @@ -68,6 +68,8 @@ static void slave() if (err == ENOENT) noent++; + edg_wll_LogUserTagProxy(ctx,"test","x"); + edg_wll_FreeContext(ctx); } printf("[%d] done, ENOENTs %d\n",pid,noent); diff --git a/org.glite.lb.client/src/connection.c b/org.glite.lb.client/src/connection.c index 232be5b..7be04a7 100644 --- a/org.glite.lb.client/src/connection.c +++ b/org.glite.lb.client/src/connection.c @@ -17,7 +17,7 @@ #include "glite/lb/context-int.h" #include "glite/lb/mini_http.h" - +#include "connection.h" static void CloseConnection(edg_wll_Context ctx, int conn_index) { @@ -116,7 +116,7 @@ int edg_wll_close_proxy(edg_wll_Context ctx) { edg_wll_plain_close(&ctx->connProxy->conn); - return edg_wll_Error(ctx, NULL, NULL); + return edg_wll_ResetError(ctx); } @@ -202,7 +202,9 @@ int edg_wll_open_proxy(edg_wll_Context ctx) { struct sockaddr_un saddr; int flags; - + int err; + char *ed = NULL; + int retries = 0; if (ctx->connProxy->conn.sock > -1) { // XXX: test path socket here? @@ -234,19 +236,48 @@ int edg_wll_open_proxy(edg_wll_Context ctx) goto err; } - if (connect(ctx->connProxy->conn.sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { - edg_wll_SetError(ctx, errno, "connect()"); + while ((err = connect(ctx->connProxy->conn.sock, (struct sockaddr *)&saddr, sizeof(saddr))) < 0 && + errno == EAGAIN && + ctx->p_tmp_timeout.tv_sec >= 0 && ctx->p_tmp_timeout.tv_usec >= 0 && + !(ctx->p_tmp_timeout.tv_sec == 0 && ctx->p_tmp_timeout.tv_usec == 0) + ) + { + struct timespec ns = { 0, PROXY_CONNECT_RETRY * 1000000 /* 10 ms */ },rem; + + nanosleep(&ns,&rem); + + ctx->p_tmp_timeout.tv_usec -= ns.tv_nsec/1000; + ctx->p_tmp_timeout.tv_usec += rem.tv_nsec/1000; + + ctx->p_tmp_timeout.tv_sec -= ns.tv_sec; + ctx->p_tmp_timeout.tv_sec += rem.tv_sec; + + if (ctx->p_tmp_timeout.tv_usec < 0) { + ctx->p_tmp_timeout.tv_usec += 1000000; + ctx->p_tmp_timeout.tv_sec--; + } + retries++; + } + + /* printf("retries %d\n",retries); */ + + if (err) { + if (errno == EAGAIN) edg_wll_SetError(ctx,ETIMEDOUT, "edg_wll_open_proxy()"); + else edg_wll_SetError(ctx, errno, "connect()"); goto err; } - return edg_wll_Error(ctx,NULL,NULL); + return edg_wll_ResetError(ctx); err: /* some error occured; close created connection */ + err = edg_wll_Error(ctx,NULL,&ed); edg_wll_close_proxy(ctx); + edg_wll_SetError(ctx,err,ed); + free(ed); - return edg_wll_Error(ctx,NULL,NULL); + return err; } diff --git a/org.glite.lb.client/src/connection.h b/org.glite.lb.client/src/connection.h index 7de349d..1b12058 100644 --- a/org.glite.lb.client/src/connection.h +++ b/org.glite.lb.client/src/connection.h @@ -1,7 +1,7 @@ #ifndef __EDG_WORKLOAD_LOGGING_CLIENT_CONNECTION_H__ #define __EDG_WORKLOAD_LOGGING_CLIENT_CONNECTION_H__ -#ident "$Header" +#ident "$Header$" int edg_wll_close(edg_wll_Context ctx); int edg_wll_open(edg_wll_Context ctx); @@ -13,5 +13,7 @@ int edg_wll_http_send_recv_proxy(edg_wll_Context, char *, const char * const *, int http_check_status(edg_wll_Context, char *); +#define PROXY_CONNECT_RETRY 10 /* ms */ + #endif /* __EDG_WORKLOAD_LOGGING_CLIENT_CONNECTION_H__ */ diff --git a/org.glite.lb.client/src/producer.c b/org.glite.lb.client/src/producer.c index ea87798..ea6cc0e 100644 --- a/org.glite.lb.client/src/producer.c +++ b/org.glite.lb.client/src/producer.c @@ -27,6 +27,7 @@ #include "glite/lb/escape.h" #include "prod_proto.h" +#include "connection.h" static const char* socket_path="/tmp/lb_proxy_store.sock"; @@ -156,7 +157,7 @@ int edg_wll_DoLogEventProxy( edg_wll_LogLine logline) { int answer; - int flags; + int flags,retries; char *name_esc,*dguser; struct sockaddr_un saddr; edg_wll_PlainConnection conn; @@ -187,6 +188,10 @@ int edg_wll_DoLogEventProxy( close(conn.sock); goto edg_wll_DoLogEventProxy_end; } + +/* non-retry variant (pre bug #18994) + * XXX: what is the EISCONN case good for? conn.sock is created above. + * if (connect(conn.sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { if(errno != EISCONN) { edg_wll_SetError(context,answer = errno,"connect()"); @@ -194,6 +199,40 @@ int edg_wll_DoLogEventProxy( goto edg_wll_DoLogEventProxy_end; } } +*/ + + retries = 0; + while ((answer = connect(conn.sock, (struct sockaddr *)&saddr, sizeof(saddr))) < 0 && + errno == EAGAIN && + context->p_tmp_timeout.tv_sec >= 0 && context->p_tmp_timeout.tv_usec >= 0 && + !(context->p_tmp_timeout.tv_sec == 0 && context->p_tmp_timeout.tv_usec == 0) + ) + { + struct timespec ns = { 0, PROXY_CONNECT_RETRY * 1000000 /* 10 ms */ },rem; + + nanosleep(&ns,&rem); + + context->p_tmp_timeout.tv_usec -= ns.tv_nsec/1000; + context->p_tmp_timeout.tv_usec += rem.tv_nsec/1000; + + context->p_tmp_timeout.tv_sec -= ns.tv_sec; + context->p_tmp_timeout.tv_sec += rem.tv_sec; + + if (context->p_tmp_timeout.tv_usec < 0) { + context->p_tmp_timeout.tv_usec += 1000000; + context->p_tmp_timeout.tv_sec--; + } + retries++; + } + + if (answer) { + if (errno == EAGAIN) edg_wll_SetError(context,answer = ETIMEDOUT,"edg_wll_DoLogEventProxy connect()"); + else edg_wll_SetError(context,answer = errno,"connect()"); + close(conn.sock); + goto edg_wll_DoLogEventProxy_end; + } + +/* just debug if (retries) printf("edg_wll_DoLogEventProxy connect retries %d\n",retries); */ /* add DG.USER to the message: */ name_esc = edg_wll_LogEscape(context->p_user_lbproxy);