-
Notifications
You must be signed in to change notification settings - Fork 980
Limit max reset frames to mitigate HTTP/2 RST floods #5232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df7f858
Limit max reset frames to mitigate HTTP/2 RST floods
ikhoon 43ce20e
Fix flaky
ikhoon 2663c40
of
ikhoon f84beb8
Update core/src/main/java/com/linecorp/armeria/common/Flags.java
ikhoon 98f0e87
Update core/src/main/java/com/linecorp/armeria/common/FlagsProvider.java
ikhoon 6723cc2
Update core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
ikhoon 1ee478b
Update core/src/main/java/com/linecorp/armeria/server/ServerConfig.java
minwoox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -694,6 +694,22 @@ default Long defaultHttp2MaxHeaderListSize() { | |
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the default maximum number RST frames that are allowed per window before the connection is | ||
|
||
| * closed. This allows to protect against the remote peer flooding us with such frames and so use up a lot | ||
ikhoon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * of CPU. Note that this flag has no effect if a user specified the value explicitly via | ||
| * {@link ServerBuilder#http2MaxResetFramesPerWindow(int, int)}. | ||
| * | ||
| * <p>The default value of this flag is | ||
| * {@value DefaultFlagsProvider#DEFAULT_HTTP2_MAX_RESET_FRAMES_PER_MINUTE}. | ||
| * Specify the {@code -Dcom.linecorp.armeria.defaultHttp2MaxResetFramesPerMinute=<integer>} JVM option | ||
| * to override the default value. {@code 0} means no protection should be applied. | ||
| */ | ||
| @Nullable | ||
| default Integer defaultHttp2MaxResetFramesPerMinute() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@linkplain Backoff#of(String) Backoff specification string} of the default {@link Backoff} | ||
| * returned by {@link Backoff#ofDefault()}. Note that this flag has no effect if a user specified the | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
95 changes: 95 additions & 0 deletions
95
core/src/test/java/com/linecorp/armeria/server/MaxResetFramesTest.java
This file contains hidden or 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,95 @@ | ||
| /* | ||
| * Copyright 2023 LINE Corporation | ||
| * | ||
| * LINE Corporation licenses this file to you 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: | ||
| * | ||
| * https://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.linecorp.armeria.server; | ||
|
|
||
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import com.spotify.futures.CompletableFutures; | ||
|
|
||
| import com.linecorp.armeria.client.ClientFactory; | ||
| import com.linecorp.armeria.client.CountingConnectionPoolListener; | ||
| import com.linecorp.armeria.client.WebClient; | ||
| import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
| import com.linecorp.armeria.common.HttpMethod; | ||
| import com.linecorp.armeria.common.HttpObject; | ||
| import com.linecorp.armeria.common.HttpRequest; | ||
| import com.linecorp.armeria.common.HttpResponse; | ||
| import com.linecorp.armeria.common.RequestHeaders; | ||
| import com.linecorp.armeria.common.SessionProtocol; | ||
| import com.linecorp.armeria.common.stream.StreamMessage; | ||
| import com.linecorp.armeria.testing.junit5.server.ServerExtension; | ||
|
|
||
| class MaxResetFramesTest { | ||
| @RegisterExtension | ||
| static final ServerExtension server = new ServerExtension() { | ||
| @Override | ||
| protected void configure(ServerBuilder sb) { | ||
| sb.idleTimeoutMillis(0); | ||
| sb.http2MaxResetFramesPerWindow(10, 60); | ||
| sb.service("/", (ctx, req) -> { | ||
| return HttpResponse.of(req.aggregate().thenApply(unused -> HttpResponse.of(200))); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| @Test | ||
| void shouldCloseConnectionWhenExceedingMaxResetFrames() { | ||
| final CountingConnectionPoolListener listener = new CountingConnectionPoolListener(); | ||
| try (ClientFactory factory = ClientFactory.builder() | ||
| .connectionPoolListener(listener) | ||
| .idleTimeoutMillis(0) | ||
| .build()) { | ||
| final WebClient client = WebClient.builder(server.uri(SessionProtocol.H2C)) | ||
| .factory(factory) | ||
| .build(); | ||
| final List<CompletableFuture<AggregatedHttpResponse>> futures = | ||
| IntStream.range(0, 11) | ||
| .mapToObj(unused -> HttpRequest.of(RequestHeaders.of(HttpMethod.POST, "/"), | ||
| StreamMessage.of(InvalidHttpObject.INSTANCE))) | ||
| .map(client::execute) | ||
| .map(HttpResponse::aggregate) | ||
| .collect(toImmutableList()); | ||
|
|
||
| CompletableFutures.successfulAsList(futures, cause -> null).join(); | ||
| assertThat(listener.opened()).isEqualTo(1); | ||
| await().untilAsserted(() -> assertThat(listener.closed()).isEqualTo(1)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * {@link WebClient} resets a stream when it receives an invalid {@link HttpObject} from | ||
| * {@link HttpRequest}. | ||
| */ | ||
| private enum InvalidHttpObject implements HttpObject { | ||
|
|
||
| INSTANCE; | ||
|
|
||
| @Override | ||
| public boolean isEndOfStream() { | ||
| return false; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: number of