Skip to content

Commit 4161f96

Browse files
erin2722MongoDB Bot
authored andcommitted
SERVER-105753 Ensure connection establishment rate limiter UX consistency with operation rate limiter (#36793)
GitOrigin-RevId: 01486ee5ef0c7f56f1ef53b04f039b9cd4270f96
1 parent 50d1023 commit 4161f96

10 files changed

+32
-214
lines changed

jstests/noPassthrough/connection_establishment_rate_limiting.js

Lines changed: 0 additions & 189 deletions
This file was deleted.

jstests/noPassthrough/connection_establishment_rate_limiting_client_disconnect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const testKillOnClientDisconnect = (conn) => {
5151
};
5252

5353
const testKillOnClientDisconnectOpts = {
54+
ingressConnectionEstablishmentRateLimiterEnabled: true,
5455
ingressConnectionEstablishmentRatePerSec: 1,
5556
ingressConnectionEstablishmentBurstSize: 1,
5657
ingressConnectionEstablishmentMaxQueueDepth: maxQueueSize,

jstests/noPassthrough/connection_establishment_rate_limiting_exemptions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ const testExemptIPsFromRateLimit = (conn) => {
4848
};
4949

5050
const testExemptIPsFromRateLimitOpts = {
51+
ingressConnectionEstablishmentRateLimiterEnabled: true,
5152
ingressConnectionEstablishmentRatePerSec: 1,
5253
ingressConnectionEstablishmentBurstSize: 1,
5354
ingressConnectionEstablishmentMaxQueueDepth: 0,
54-
maxEstablishingConnectionsOverride: {ranges: [exemptIP]},
55+
ingressConnectionEstablishmentRateLimiterBypass: {ranges: [exemptIP]},
5556
};
5657
runTestStandaloneParamsSetAtStartup(testExemptIPsFromRateLimitOpts, testExemptIPsFromRateLimit);
5758
runTestStandaloneParamsSetAtRuntime(testExemptIPsFromRateLimitOpts, testExemptIPsFromRateLimit);

jstests/noPassthrough/connection_establishment_rate_limiting_proxy_protocol.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ let rs = new ReplSetTest({
3232
"proxyPort": egressPort,
3333
config: "jstests/noPassthrough/libs/max_conns_override_config.yaml",
3434
setParameter: {
35+
ingressConnectionEstablishmentRateLimiterEnabled: true,
3536
ingressConnectionEstablishmentRatePerSec: 1,
3637
ingressConnectionEstablishmentBurstSize: 1,
3738
ingressConnectionEstablishmentMaxQueueDepth: 0,
38-
maxEstablishingConnectionsOverride: {ranges: [exemptIP]},
39+
ingressConnectionEstablishmentRateLimiterBypass: {ranges: [exemptIP]},
3940
featureFlagRateLimitIngressConnectionEstablishment: true
4041
}
4142
}
@@ -67,8 +68,7 @@ rs.initiate();
6768
// Let connections through again.
6869
rs.getPrimary().adminCommand({
6970
setParameter: 1,
70-
ingressConnectionEstablishmentRatePerSec: 10,
71-
ingressConnectionEstablishmentBurstSize: 500,
71+
ingressConnectionEstablishmentRateLimiterEnabled: false,
7272
});
7373

7474
// Start up a proxy protocol server with an exempt IP as its egress address. Ensure that non-exempt
@@ -81,8 +81,7 @@ rs.getPrimary().adminCommand({
8181
// Reset the rate limiter to use lower values again.
8282
rs.getPrimary().adminCommand({
8383
setParameter: 1,
84-
ingressConnectionEstablishmentRatePerSec: 1,
85-
ingressConnectionEstablishmentBurstSize: 1,
84+
ingressConnectionEstablishmentRateLimiterEnabled: true,
8685
});
8786

8887
// One token will be consumed by a non-exempt IP.

jstests/noPassthrough/connection_establishment_rate_limiting_stats.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const testRateLimiterStats = (conn) => {
9393
};
9494

9595
const testRateLimiterStatsOpts = {
96+
ingressConnectionEstablishmentRateLimiterEnabled: true,
9697
ingressConnectionEstablishmentRatePerSec: 1,
9798
ingressConnectionEstablishmentBurstSize: 1,
9899
ingressConnectionEstablishmentMaxQueueDepth: maxQueueSize,

jstests/noPassthrough/max_conns_override_runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Tests using a server parameter to set `maxIncomingConnectionsOverride` and
2-
// `maxEstablishingConnectionsOverride` at runtime.
2+
// `ingressConnectionEstablishmentRateLimiterBypass` at runtime.
33

44
const maxIncoming = "maxIncomingConnectionsOverride";
5-
const maxEstablishing = "maxEstablishingConnectionsOverride";
5+
const maxEstablishing = "ingressConnectionEstablishmentRateLimiterBypass";
66

77
function runTest(args, testFunc) {
88
// Run tests in isolation to make sure we always start with a clean slate.

src/mongo/transport/session_establishment_rate_limiter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ SessionEstablishmentRateLimiter* SessionEstablishmentRateLimiter::get(ServiceCon
6565

6666

6767
Status SessionEstablishmentRateLimiter::throttleIfNeeded(Client* client) {
68-
// We can short-circuit if the rate limit is unlimited, which probably means the feature
69-
// is off.
70-
if (gIngressConnectionEstablishmentRatePerSec.loadRelaxed() ==
71-
std::numeric_limits<int>::max()) {
72-
// Note that in this case, no metrics are maintained.
73-
return Status::OK();
74-
}
75-
7668
// Check if the session is exempt from rate limiting based on its IP.
7769
serverGlobalParams.maxEstablishingConnsOverride.refreshSnapshot(_maxEstablishingConnsOverride);
7870
if (_maxEstablishingConnsOverride &&

src/mongo/transport/session_workflow.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include "mongo/transport/session_manager.h"
8181
#include "mongo/transport/session_workflow.h"
8282
#include "mongo/transport/transport_layer_manager.h"
83+
#include "mongo/transport/transport_options_gen.h"
8384
#include "mongo/util/assert_util.h"
8485
#include "mongo/util/clock_source.h"
8586
#include "mongo/util/concurrency/idle_thread_block.h"
@@ -817,7 +818,8 @@ void SessionWorkflow::Impl::_scheduleIteration() try {
817818
const auto fcvSnapshot =
818819
serverGlobalParams.featureCompatibility.acquireFCVSnapshot();
819820
if (gFeatureFlagRateLimitIngressConnectionEstablishment
820-
.isEnabledUseLatestFCVWhenUninitialized(fcvSnapshot)) {
821+
.isEnabledUseLatestFCVWhenUninitialized(fcvSnapshot) &&
822+
gIngressConnectionEstablishmentRateLimiterEnabled.load()) {
821823
uassertStatusOK(session()
822824
->getTransportLayer()
823825
->getSessionManager()

src/mongo/transport/session_workflow_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ class ConnectionEstablishmentQueueingTest : public SessionWorkflowTest {
606606

607607
RAIIServerParameterControllerForTest featureFlagController{
608608
"featureFlagRateLimitIngressConnectionEstablishment", true};
609+
RAIIServerParameterControllerForTest featureEnabled{
610+
"ingressConnectionEstablishmentRateLimiterEnabled", true};
609611
unittest::MinimumLoggedSeverityGuard logSeverityGuard{logv2::LogComponent::kDefault,
610612
logv2::LogSeverity::Debug(4)};
611613
};
@@ -680,7 +682,8 @@ TEST_F(ConnectionEstablishmentQueueingTest, InterruptQueuedEstablishments) {
680682
TEST_F(ConnectionEstablishmentQueueingTest, BypassQueueingEstablishment) {
681683
std::string ip = "127.0.0.1";
682684
RAIIServerParameterControllerForTest exemptionsGuard(
683-
"maxEstablishingConnectionsOverride", BSON("ranges" << BSONArray(BSON("0" << ip))));
685+
"ingressConnectionEstablishmentRateLimiterBypass",
686+
BSON("ranges" << BSONArray(BSON("0" << ip))));
684687
RAIIServerParameterControllerForTest refreshRate{"ingressConnectionEstablishmentRatePerSec",
685688
1.0};
686689
RAIIServerParameterControllerForTest burstSize{"ingressConnectionEstablishmentBurstSize", 1};

src/mongo/transport/transport_options.idl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,25 @@ server_parameters:
8181
override_set: true
8282
redact: false
8383

84-
maxEstablishingConnectionsOverride:
85-
description: "A list of CIDRs to be exempted from the max establishing limits"
84+
ingressConnectionEstablishmentRateLimiterBypass:
85+
description: "A list of CIDRs to be exempted from the ingress connection establishment rate limit"
8686
set_at: [startup, runtime]
8787
cpp_class:
8888
name: "MaxEstablishingConnectionsOverrideServerParameter"
8989
# Expects the payload to be an instance of `ConnectionListParameters`.
9090
override_set: true
9191
redact: false
92-
92+
93+
ingressConnectionEstablishmentRateLimiterEnabled:
94+
description: "Whether the ingress connection establishment rate limiter is enabled or not"
95+
set_at: [startup, runtime]
96+
cpp_varname: gIngressConnectionEstablishmentRateLimiterEnabled
97+
cpp_vartype: Atomic<bool>
98+
default: false
99+
redact: false
100+
93101
ingressConnectionEstablishmentRatePerSec:
94-
description: "The number of new connections that will be allowed to establish per second"
102+
description: "The number of new ingress connections that will be allowed to establish per second"
95103
set_at: [startup, runtime]
96104
cpp_varname: gIngressConnectionEstablishmentRatePerSec
97105
cpp_vartype: Atomic<int32_t>
@@ -103,7 +111,7 @@ server_parameters:
103111

104112
ingressConnectionEstablishmentBurstSize:
105113
description: >-
106-
The maximum number of connection establishments that will be admitted before rate-limiting
114+
The maximum number of ingress connection establishments that will be admitted before rate-limiting
107115
kicks in (ie, the burst size of the bucket)
108116
set_at: [startup, runtime]
109117
cpp_varname: gIngressConnectionEstablishmentBurstSize
@@ -117,8 +125,8 @@ server_parameters:
117125
ingressConnectionEstablishmentMaxQueueDepth:
118126
description: >-
119127
The maximum size of the connection establishment queue, after which the server will begin
120-
rejecting new connections. A queue size of 0 indicates that connections will be rejected if
121-
they cannot immediately be admitted.
128+
rejecting new ingress connections. A queue size of 0 indicates that connections will be
129+
rejected if they cannot immediately be admitted.
122130
set_at: [startup, runtime]
123131
cpp_varname: gIngressConnectionEstablishmentMaxQueueDepth
124132
cpp_vartype: Atomic<int32_t>

0 commit comments

Comments
 (0)