-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new handler to close on inbound http/2 protocol errors (#1701)
* Initial commit * Unit test * Http2OrHttpHanlder unit test * Rename metric * Add missing license * Remove unneeded go-away logic as it's already handled by netty * Rename to try and make it clear that the new handler isn't doing all that much
- Loading branch information
Showing
5 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
zuul-core/src/main/java/com/netflix/zuul/netty/server/http2/Http2ConnectionErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2023 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.zuul.netty.server.http2; | ||
|
||
import com.netflix.zuul.netty.SpectatorUtils; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.handler.codec.http2.Http2Exception; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Logs and tracks connection errors. The actual | ||
* sending of the go-away and closing the connection is handled by netty in {@link io.netty.handler.codec.http2.Http2ConnectionHandler} | ||
* onConnectionError | ||
* | ||
* See also, {@link com.netflix.netty.common.channel.config.CommonChannelConfigKeys#http2CatchConnectionErrors} | ||
* @author Justin Guerra | ||
* @since 11/14/23 | ||
*/ | ||
public class Http2ConnectionErrorHandler extends ChannelInboundHandlerAdapter { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(Http2ConnectionErrorHandler.class); | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { | ||
if(cause instanceof Http2Exception http2Exception) { | ||
LOG.debug("Received Http/2 connection error", cause); | ||
SpectatorUtils.newCounter("server.connection.http2.connection.exception", http2Exception.error().name()).increment(); | ||
} else { | ||
ctx.fireExceptionCaught(cause); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...re/src/test/java/com/netflix/zuul/netty/server/http2/Http2ConnectionErrorHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright 2023 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.zuul.netty.server.http2; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.channel.embedded.EmbeddedChannel; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Justin Guerra | ||
* @since 11/15/23 | ||
*/ | ||
class Http2ConnectionErrorHandlerTest { | ||
|
||
private EmbeddedChannel channel; | ||
private ExceptionCapturingHandler exceptionCapturingHandler; | ||
|
||
@BeforeEach | ||
void setup() { | ||
exceptionCapturingHandler = new ExceptionCapturingHandler(); | ||
channel = new EmbeddedChannel(new Http2ConnectionErrorHandler(), exceptionCapturingHandler); | ||
} | ||
|
||
@Test | ||
public void nonHttp2ExceptionsPassedUpPipeline() { | ||
RuntimeException exception = new RuntimeException(); | ||
channel.pipeline().fireExceptionCaught(exception); | ||
assertEquals(exception, exceptionCapturingHandler.caught); | ||
} | ||
|
||
private static class ExceptionCapturingHandler extends ChannelInboundHandlerAdapter { | ||
|
||
private Throwable caught; | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { | ||
this.caught = cause; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters