Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 36C4318EF6 for ; Thu, 8 Oct 2015 18:16:17 +0000 (UTC) Received: (qmail 65513 invoked by uid 500); 8 Oct 2015 18:16:17 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 65488 invoked by uid 500); 8 Oct 2015 18:16:17 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 65479 invoked by uid 99); 8 Oct 2015 18:16:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2015 18:16:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 01B48E0BF0; Thu, 8 Oct 2015 18:16:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bpetri@apache.org To: commits@celix.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: celix git commit: CELIX-190: Fixed race condition in endpoint discovery Date: Thu, 8 Oct 2015 18:16:17 +0000 (UTC) Repository: celix Updated Branches: refs/heads/develop cec955da8 -> 4fc908f61 CELIX-190: Fixed race condition in endpoint discovery Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/4fc908f6 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/4fc908f6 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/4fc908f6 Branch: refs/heads/develop Commit: 4fc908f611ce7dad3790bfaccd23601de2372f4f Parents: cec955d Author: Bjoern Petri Authored: Thu Oct 8 20:15:40 2015 +0200 Committer: Bjoern Petri Committed: Thu Oct 8 20:15:40 2015 +0200 ---------------------------------------------------------------------- .../private/src/endpoint_discovery_poller.c | 4 ++- .../private/src/endpoint_discovery_server.c | 38 ++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/4fc908f6/remote_services/discovery/private/src/endpoint_discovery_poller.c ---------------------------------------------------------------------- diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c index 631f063..7fb4786 100644 --- a/remote_services/discovery/private/src/endpoint_discovery_poller.c +++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c @@ -101,12 +101,13 @@ celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_con return CELIX_BUNDLE_EXCEPTION; } + (*poller)->running = true; + status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller); if (status != CELIX_SUCCESS) { return status; } - (*poller)->running = true; status = celixThreadMutex_unlock(&(*poller)->pollerLock); @@ -362,6 +363,7 @@ static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L); res = curl_easy_perform(curl); + curl_easy_cleanup(curl); } http://git-wip-us.apache.org/repos/asf/celix/blob/4fc908f6/remote_services/discovery/private/src/endpoint_discovery_server.c ---------------------------------------------------------------------- diff --git a/remote_services/discovery/private/src/endpoint_discovery_server.c b/remote_services/discovery/private/src/endpoint_discovery_server.c index 9c41a4d..818d239 100644 --- a/remote_services/discovery/private/src/endpoint_discovery_server.c +++ b/remote_services/discovery/private/src/endpoint_discovery_server.c @@ -294,10 +294,6 @@ static celix_status_t endpointDiscoveryServer_getEndpoints(endpoint_discovery_se return CELIX_ENOMEM; } - status = celixThreadMutex_lock(&server->serverLock); - if (status != CELIX_SUCCESS) { - return CELIX_BUNDLE_EXCEPTION; - } hash_map_iterator_pt iter = hashMapIterator_create(server->entries); while (hashMapIterator_hasNext(iter)) { @@ -312,11 +308,6 @@ static celix_status_t endpointDiscoveryServer_getEndpoints(endpoint_discovery_se } hashMapIterator_destroy(iter); - status = celixThreadMutex_unlock(&server->serverLock); - if (status != CELIX_SUCCESS) { - return CELIX_BUNDLE_EXCEPTION; - } - return status; } @@ -346,12 +337,18 @@ static int endpointDiscoveryServer_returnAllEndpoints(endpoint_discovery_server_ int status = CIVETWEB_REQUEST_NOT_HANDLED; array_list_pt endpoints = NULL; - endpointDiscoveryServer_getEndpoints(server, NULL, &endpoints); - if (endpoints) { - status = endpointDiscoveryServer_writeEndpoints(conn, endpoints); - arrayList_destroy(endpoints); - } + if (celixThreadMutex_lock(&server->serverLock) == CELIX_SUCCESS) { + endpointDiscoveryServer_getEndpoints(server, NULL, &endpoints); + if (endpoints) { + status = endpointDiscoveryServer_writeEndpoints(conn, endpoints); + + arrayList_destroy(endpoints); + } + + + celixThreadMutex_unlock(&server->serverLock); + } return status; } @@ -361,11 +358,16 @@ static int endpointDiscoveryServer_returnEndpoint(endpoint_discovery_server_pt s int status = CIVETWEB_REQUEST_NOT_HANDLED; array_list_pt endpoints = NULL; - endpointDiscoveryServer_getEndpoints(server, endpoint_id, &endpoints); - if (endpoints) { - status = endpointDiscoveryServer_writeEndpoints(conn, endpoints); - arrayList_destroy(endpoints); + if (celixThreadMutex_lock(&server->serverLock) == CELIX_SUCCESS) { + endpointDiscoveryServer_getEndpoints(server, endpoint_id, &endpoints); + if (endpoints) { + status = endpointDiscoveryServer_writeEndpoints(conn, endpoints); + + arrayList_destroy(endpoints); + } + + celixThreadMutex_unlock(&server->serverLock); } return status;