if ( (index = ConnectionIndex(ctx, ctx->srvName, ctx->srvPort)) == -1 ) {
                /* no such open connection in pool */
                if (ctx->connections->connOpened == ctx->connections->poolSize)
-                       if(ReleaseConnection(ctx, NULL, 0)) goto end;
+                       if(ReleaseConnection(ctx, NULL, 0)) {
+                               edg_wll_poolUnlock(); 
+                               goto end;
+                       }
                
                index = AddConnection(ctx, ctx->srvName, ctx->srvPort);
                if (index < 0) {
                     edg_wll_SetError(ctx,EAGAIN,"connection pool size exceeded");
+                   edg_wll_poolUnlock(); 
                    goto end;
                }
 
 
                if (ctx->connections->connOpened == ctx->connections->poolSize)
                        if (ReleaseConnection(ctx, NULL, 0)) {
                                answer = edg_wll_SetError(ctx,EAGAIN,"cannot release connection (pool size exceeded)");
+                               edg_wll_poolUnlock();
                                goto edg_wll_log_connect_end;
                        }
                index = AddConnection(ctx, ctx->p_destination, ctx->p_dest_port);
                if (index < 0) {
                     answer = edg_wll_SetError(ctx,EAGAIN,"cannot add connection to pool");
+                   edg_wll_poolUnlock();
                    goto edg_wll_log_connect_end;
                }
 #ifdef EDG_WLL_LOG_STUB