You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/08/15 03:19:48 UTC
[GitHub] chickenlj closed pull request #2245: Fixissue#1343 team4
chickenlj closed pull request #2245: Fixissue#1343 team4
URL: https://github.com/apache/incubator-dubbo/pull/2245
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
index e9d5e6b567..2484a32942 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
@@ -30,6 +30,7 @@
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.config.support.Parameter;
+import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
@@ -351,12 +352,40 @@ public synchronized void unexport() {
unexported = true;
}
- @SuppressWarnings({"unchecked", "rawtypes"})
+ private static void clearRandomPort(String protocol) {
+ protocol = protocol.toLowerCase();
+ RANDOM_PORT_MAP.remove(protocol);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
private void doExportUrls() {
List<URL> registryURLs = loadRegistries(true);
for (ProtocolConfig protocolConfig : protocols) {
- doExportUrlsFor1Protocol(protocolConfig, registryURLs);
+ while(true) {
+ try {
+ doExportUrlsFor1Protocol(protocolConfig, registryURLs);
+ break;
+ } catch (RpcException e) {
+ if (e.getMessage().contains("Already in use")&&e.getMessage().contains("Failed to bind")) {
+ //logger.error("doExportUrls port failure and try again: " + e.getMessage(), e);
+ clearRandomPort(getProtocolName(protocolConfig));
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException ignored) {}
+ } else {
+ throw e;
+ }
+ }
+ }
+ }
+ }
+
+ private String getProtocolName(ProtocolConfig protocolConfig) {
+ String name = protocolConfig.getName();
+ if (name == null || name.length() == 0) {
+ name = "dubbo";
}
+ return name;
}
private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> registryURLs) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org