Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #7265 AbstractRegistryFactory#getRegistry and destroyAll methods compete for locks in multiple threads #7273

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,22 @@ public static void destroyAll() {
}
}

@Override
public Registry getRegistry(URL url) {
private Registry getDefaultNopRegistryIfDestroyed() {
if (destroyed.get()) {
LOGGER.warn("All registry instances have been destroyed, failed to fetch any instance. " +
"Usually, this means no need to try to do unnecessary redundant resource clearance, all registries has been taken care of.");
return DEFAULT_NOP_REGISTRY;
}
return null;
}

@Override
public Registry getRegistry(URL url) {

Registry defaultNopRegistry = getDefaultNopRegistryIfDestroyed();
if (null != defaultNopRegistry) {
return defaultNopRegistry;
}

url = URLBuilder.from(url)
.setPath(RegistryService.class.getName())
Expand All @@ -126,6 +135,13 @@ public Registry getRegistry(URL url) {
// Lock the registry access process to ensure a single instance of the registry
LOCK.lock();
try {
// double check
// fix https://github.com/apache/dubbo/issues/7265.
defaultNopRegistry = getDefaultNopRegistryIfDestroyed();
if (null != defaultNopRegistry) {
return defaultNopRegistry;
}

Registry registry = REGISTRIES.get(key);
if (registry != null) {
return registry;
Expand Down