Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up resources when trying to update eureka nodes. Lingering reso…

…urces may create problems when the server is running for a long time.
  • Loading branch information...
commit 3276bb53cf646dcb176e4f7c0104df7fcef4f0e8 1 parent b8a3a1b
Karthik Ranganathan authored
View
16 eureka-client/src/main/java/com/netflix/discovery/shared/EurekaJerseyClient.java
@@ -119,6 +119,20 @@ public void run() {
HTTP_CONNECTION_CLEANER_INTERVAL_MS);
}
- }
+
+ /**
+ * Clean up resources.
+ */
+ public void destroyResources() {
+ if (this.eurekaConnCleaner != null) {
+ this.eurekaConnCleaner.cancel();
+ }
+ if (this.apacheHttpClient != null) {
+ this.apacheHttpClient.destroy();
+ }
+ }
+ }
+
+
}
View
13 eureka-core/src/main/java/com/netflix/eureka/PeerAwareInstanceRegistry.java
@@ -286,9 +286,10 @@ private void updatePeerEurekaNodes() {
logger.warn("The replica size seems to be empty. Check the route 53 DNS Registry");
return;
}
- if (!replicaNodes.equals(peerEurekaNodes.get())) {
+ List<PeerEurekaNode> existingReplicaNodes = peerEurekaNodes.get();
+ if (!replicaNodes.equals(existingReplicaNodes)) {
List<String> previousServiceUrls = new ArrayList<String>();
- for (PeerEurekaNode node : peerEurekaNodes.get()) {
+ for (PeerEurekaNode node : existingReplicaNodes) {
previousServiceUrls.add(node.getServiceUrl());
}
List<String> currentServiceUrls = new ArrayList<String>();
@@ -299,6 +300,14 @@ private void updatePeerEurekaNodes() {
"Updating the replica nodes as they seem to have changed from {} to {} ",
previousServiceUrls, currentServiceUrls);
peerEurekaNodes.set(replicaNodes);
+ for (PeerEurekaNode existingReplicaNode: existingReplicaNodes) {
+ existingReplicaNode.destroyResources();
+ }
+ }
+ else {
+ for (PeerEurekaNode replicaNode : replicaNodes) {
+ replicaNode.destroyResources();
+ }
}
}
View
9 eureka-core/src/main/java/com/netflix/eureka/cluster/PeerEurekaNode.java
@@ -467,5 +467,14 @@ public void disableStatusReplication() {
public void enableStatusReplication() {
this.statusReplication = true;
}
+
+ /**
+ * Destroy the resources created for communication with the Peer Eureka Server.
+ */
+ public void destroyResources () {
+ if (jerseyClient != null) {
+ jerseyClient.destroyResources();
+ }
+ }
}
View
2  eureka-server/conf/sampleclient/sample-eureka-client.properties
@@ -11,7 +11,7 @@ eureka.region=default
#Name of the application to be identified by other services
-eureka.name=sample-eureka-client
+eureka.name=sampleEurekaClient
#Virtual host name by which the clients identifies this service
#eureka.vipAddress=eureka.mydomain.net
View
2  eureka-server/conf/sampleservice/sample-eureka-service.properties
@@ -11,7 +11,7 @@ eureka.region=default
#Name of the application to be identified by other services
-eureka.name=sample-eureka-service
+eureka.name=sampleEurekaService
#Virtual host name by which the clients identifies this service
eureka.vipAddress=sampleservice.mydomain.net
Please sign in to comment.
Something went wrong with that request. Please try again.