Skip to content

Commit

Permalink
Fixing exception propagation from Http2OrHttpHandler to server transport
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Sep 23, 2022
1 parent 6ed7c42 commit 6bc350e
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.netty.handler.ssl.ApplicationProtocolNames;
import io.netty.handler.ssl.ApplicationProtocolNegotiationHandler;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.AttributeKey;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -34,13 +35,15 @@
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.http.HttpChannel;
import org.opensearch.http.HttpHandlingSettings;
import org.opensearch.http.netty4.Netty4HttpChannel;
import org.opensearch.http.netty4.Netty4HttpServerTransport;
import org.opensearch.security.ssl.SecurityKeyStore;
import org.opensearch.security.ssl.SslExceptionHandler;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.SharedGroupFactory;

public class SecuritySSLNettyHttpServerTransport extends Netty4HttpServerTransport {
static final AttributeKey<Netty4HttpChannel> HTTP_CHANNEL_KEY = AttributeKey.valueOf("opensearch-http-channel");

private static final Logger logger = LogManager.getLogger(SecuritySSLNettyHttpServerTransport.class);
private final SecurityKeyStore sks;
Expand Down Expand Up @@ -94,6 +97,19 @@ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) thr
throw new IllegalStateException("Unknown application protocol: " + protocol);
}
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
Netty4HttpChannel channel = ctx.channel().attr(HTTP_CHANNEL_KEY).get();
if (channel != null) {
if (cause instanceof Error) {
onException(channel, new Exception(cause));
} else {
onException(channel, (Exception) cause);
}
}
}
}

protected SSLHttpChannelHandler(Netty4HttpServerTransport transport, final HttpHandlingSettings handlingSettings, final SecurityKeyStore odsks) {
Expand Down

0 comments on commit 6bc350e

Please sign in to comment.