celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject celix git commit: CELIX-190: Fixed race condition in endpoint discovery
Date Thu, 08 Oct 2015 18:16:17 GMT
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 <bpetri@apache.org>
Authored: Thu Oct 8 20:15:40 2015 +0200
Committer: Bjoern Petri <bpetri@apache.org>
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;


Mime
View raw message