You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2023/02/20 07:46:21 UTC
[servicecomb-java-chassis] branch 2.8.x updated: [SCB-2771]fix MicroserviceVersions concurrent access problem (#3637)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch 2.8.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/2.8.x by this push:
new f87a75c90 [SCB-2771]fix MicroserviceVersions concurrent access problem (#3637)
f87a75c90 is described below
commit f87a75c9089be0f283dc3c3b0ece1f3a3d711b52
Author: liubao68 <bi...@qq.com>
AuthorDate: Fri Feb 17 21:33:17 2023 +0800
[SCB-2771]fix MicroserviceVersions concurrent access problem (#3637)
---
.../registry/consumer/MicroserviceVersions.java | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
index da5f99cb5..563f872b6 100644
--- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
+++ b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
@@ -42,6 +42,8 @@ import org.apache.servicecomb.registry.definition.MicroserviceNameParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
+
public class MicroserviceVersions {
private static final Logger LOGGER = LoggerFactory.getLogger(MicroserviceVersions.class);
@@ -120,13 +122,18 @@ public class MicroserviceVersions {
return shortName;
}
+ @VisibleForTesting
public Map<String, MicroserviceVersion> getVersions() {
- return versions;
+ synchronized (lock) {
+ return versions;
+ }
}
@SuppressWarnings("unchecked")
public <T extends MicroserviceVersion> T getVersion(String serviceId) {
- return (T) versions.get(serviceId);
+ synchronized (lock) {
+ return (T) versions.get(serviceId);
+ }
}
public String getRevision() {
@@ -318,10 +325,11 @@ public class MicroserviceVersions {
}
public void destroy() {
- for (MicroserviceVersion microserviceVersion : versions.values()) {
- microserviceVersion.destroy();
+ synchronized (lock) {
+ for (MicroserviceVersion microserviceVersion : versions.values()) {
+ microserviceVersion.destroy();
+ }
}
-
appManager.getEventBus().post(new DestroyMicroserviceEvent(this));
}
}