tisonkun commented on issue #20078:
URL: https://github.com/apache/pulsar/issues/20078#issuecomment-1505385185

   I made a patch to improve the exception here, but I don't know if throwing 
an exception instead of return null and triggering NPE changes other call 
points. You can investigate deeper and submit a patch with the investigation, 
or merging this patch in your deployment and report if it works well:
   
   ```diff
   diff --git 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/jetty/tls/JettySslContextFactory.java
 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/jetty/tls/JettySslContextFactory.java
   index 46a8604599..163e1ed01f 100644
   --- 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/jetty/tls/JettySslContextFactory.java
   +++ 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/jetty/tls/JettySslContextFactory.java
   @@ -18,6 +18,8 @@
     */
    package org.apache.pulsar.jetty.tls;
    
   +import java.io.IOException;
   +import java.security.GeneralSecurityException;
    import java.util.Set;
    import javax.net.ssl.SSLContext;
    import lombok.extern.slf4j.Slf4j;
   @@ -110,7 +112,11 @@ public class JettySslContextFactory {
    
            @Override
            public SSLContext getSslContext() {
   -            return sslCtxRefresher.get();
   +            try {
   +                return sslCtxRefresher.get();
   +            } catch (GeneralSecurityException | IOException e) {
   +                return null;
   +            }
            }
        }
    }
   diff --git 
a/pulsar-common/src/main/java/org/apache/pulsar/common/util/SslContextAutoRefreshBuilder.java
 
b/pulsar-common/src/main/java/org/apache/pulsar/common/util/SslContextAutoRefreshBuilder.java
   index 8c8f580046..e071c315fe 100644
   --- 
a/pulsar-common/src/main/java/org/apache/pulsar/common/util/SslContextAutoRefreshBuilder.java
   +++ 
b/pulsar-common/src/main/java/org/apache/pulsar/common/util/SslContextAutoRefreshBuilder.java
   @@ -72,18 +72,19 @@ public abstract class SslContextAutoRefreshBuilder<T> {
         *
         * @return
         */
   -    public T get() {
   +    public T get() throws GeneralSecurityException, IOException {
            T ctx = getSslContext();
            if (ctx == null) {
                try {
   -                update();
   +                ctx = update();
                    lastRefreshTime = System.currentTimeMillis();
   -                return getSslContext();
   +                return ctx;
                } catch (GeneralSecurityException | IOException e) {
                    log.error("Exception while trying to refresh ssl Context 
{}", e.getMessage(), e);
   +                throw e;
                }
            } else {
   -            long now = System.currentTimeMillis();
   +            final long now = System.currentTimeMillis();
                if (refreshTime <= 0 || now > (lastRefreshTime + refreshTime)) {
                    if (needUpdate()) {
                        try {
   @@ -91,10 +92,11 @@ public abstract class SslContextAutoRefreshBuilder<T> {
                            lastRefreshTime = now;
                        } catch (GeneralSecurityException | IOException e) {
                            log.error("Exception while trying to refresh ssl 
Context {} ", e.getMessage(), e);
   +                        throw e;
                        }
                    }
                }
   +            return ctx;
            }
   -        return ctx;
        }
    }
   diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
   index d63b04b673..117acae147 100644
   --- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
   +++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java
   @@ -189,9 +189,10 @@ public class DirectProxyHandler {
    
            b.handler(new ChannelInitializer<SocketChannel>() {
                @Override
   -            protected void initChannel(SocketChannel ch) {
   -                ch.pipeline().addLast("consolidation", new 
FlushConsolidationHandler(1024,
   -                        true));
   +            protected void initChannel(SocketChannel ch) throws Exception {
   +                ch.pipeline().addLast(
   +                        "consolidation",
   +                        new FlushConsolidationHandler(1024, true));
                    if (tlsEnabledWithBroker) {
                        String host = targetBrokerAddress.getHostString();
                        int port = targetBrokerAddress.getPort();
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to