sijie closed pull request #1811: Improve logging when we fail to bind on server
ports
URL: https://github.com/apache/incubator-pulsar/pull/1811
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/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
index 115c30c88c..6a823f4806 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
@@ -287,8 +287,14 @@ public void start() throws Exception {
ServiceConfiguration serviceConfig = pulsar.getConfiguration();
bootstrap.childHandler(new PulsarChannelInitializer(this,
serviceConfig, false));
+
// Bind and start to accept incoming connections.
- bootstrap.bind(new InetSocketAddress(pulsar.getBindAddress(),
port)).sync();
+ InetSocketAddress addr = new
InetSocketAddress(pulsar.getBindAddress(), port);
+ try {
+ bootstrap.bind(addr).sync();
+ } catch (Exception e) {
+ throw new IOException("Failed to bind Pulsar broker on " + addr,
e);
+ }
log.info("Started Pulsar Broker service on port {}", port);
if (serviceConfig.isTlsEnabled()) {
diff --git
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyService.java
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyService.java
index 28af1abf36..48d643b7c8 100644
---
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyService.java
+++
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyService.java
@@ -24,6 +24,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicReference;
@@ -113,7 +114,11 @@ public void start() throws Exception {
bootstrap.childHandler(new ServiceChannelInitializer(this,
proxyConfig, false));
// Bind and start to accept incoming connections.
- bootstrap.bind(proxyConfig.getServicePort()).sync();
+ try {
+ bootstrap.bind(proxyConfig.getServicePort()).sync();
+ } catch (Exception e) {
+ throw new IOException("Failed to bind Pulsar Proxy on port " +
proxyConfig.getServicePort(), e);
+ }
LOG.info("Started Pulsar Proxy at {}", serviceUrl);
if (proxyConfig.isTlsEnabledInProxy()) {
@@ -175,7 +180,7 @@ public void
setConfigurationCacheService(ConfigurationCacheService configuration
public Semaphore getLookupRequestSemaphore() {
return lookupRequestSemaphore.get();
}
-
+
public EventLoopGroup getWorkerGroup() {
return workerGroup;
}
diff --git
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
index c8a60cb0fe..f7a4f28af1 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
@@ -18,8 +18,15 @@
*/
package org.apache.pulsar.proxy.server;
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+import com.google.common.collect.Lists;
+
+import io.netty.util.concurrent.DefaultThreadFactory;
+
+import java.io.IOException;
import java.net.URI;
import java.security.GeneralSecurityException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
@@ -29,6 +36,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.pulsar.common.util.ObjectMapperFactory;
import org.apache.pulsar.common.util.SecurityUtility;
+import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
@@ -46,11 +54,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
-import com.google.common.collect.Lists;
-
-import io.netty.util.concurrent.DefaultThreadFactory;
-
/**
* Manages web-service startup/stop on jetty server.
*
@@ -78,7 +81,7 @@ public WebServer(ProxyConfiguration config) {
config.isTlsAllowInsecureConnection(),
config.getTlsTrustCertsFilePath(),
config.getTlsCertificateFilePath(),
- config.getTlsKeyFilePath(),
+ config.getTlsKeyFilePath(),
config.getTlsRequireTrustedClientCertOnConnect());
ServerConnector tlsConnector = new ServerConnector(server, 1,
1, sslCtxFactory);
tlsConnector.setPort(config.getWebServicePortTls());
@@ -124,7 +127,7 @@ public void addRestResources(String basePath, String
javaPackages, String attrib
context.setAttribute(attribute, attributeValue);
handlers.add(context);
}
-
+
public int getExternalServicePort() {
return externalServicePort;
}
@@ -146,7 +149,17 @@ public void start() throws Exception {
handlerCollection.setHandlers(new Handler[] { contexts, new
DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
- server.start();
+ try {
+ server.start();
+ } catch (Exception e) {
+ List<Integer> ports = new ArrayList<>();
+ for (Connector c : server.getConnectors()) {
+ if (c instanceof ServerConnector) {
+ ports.add(((ServerConnector) c).getPort());
+ }
+ }
+ throw new IOException("Failed to start HTTP server on ports " +
ports, e);
+ }
log.info("Server started at end point {}", getServiceUri());
}
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services