|
64 | 64 | configureFailPoint: 'failCommand', mode: 'off') |
65 | 65 | end |
66 | 66 | end |
| 67 | + |
| 68 | + describe 'Connection Pool Backpressure' do |
| 69 | + min_server_fcv '8.2' |
| 70 | + require_topology :single |
| 71 | + |
| 72 | + let(:subscriber) { Mrss::EventSubscriber.new } |
| 73 | + |
| 74 | + let(:client) do |
| 75 | + new_local_client( |
| 76 | + SpecConfig.instance.addresses, |
| 77 | + SpecConfig.instance.all_test_options.merge( |
| 78 | + max_connecting: 100, |
| 79 | + max_pool_size: 100, |
| 80 | + ), |
| 81 | + ).tap do |client| |
| 82 | + client.subscribe(Mongo::Monitoring::CONNECTION_POOL, subscriber) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + after do |
| 87 | + sleep 1 |
| 88 | + admin_db = root_authorized_client.use('admin').database |
| 89 | + |
| 90 | + if defined?(@prev_ingressConnectionEstablishmentRateLimiterEnabled) && |
| 91 | + defined?(@prev_ingressConnectionEstablishmentRatePerSec) && |
| 92 | + defined?(@prev_ingressConnectionEstablishmentBurstCapacitySecs) && |
| 93 | + defined?(@prev_ingressConnectionEstablishmentMaxQueueDepth) |
| 94 | + admin_db.command( |
| 95 | + setParameter: 1, |
| 96 | + ingressConnectionEstablishmentRateLimiterEnabled: @prev_ingressConnectionEstablishmentRateLimiterEnabled, |
| 97 | + ) |
| 98 | + admin_db.command( |
| 99 | + setParameter: 1, |
| 100 | + ingressConnectionEstablishmentRatePerSec: @prev_ingressConnectionEstablishmentRatePerSec, |
| 101 | + ) |
| 102 | + admin_db.command( |
| 103 | + setParameter: 1, |
| 104 | + ingressConnectionEstablishmentBurstCapacitySecs: @prev_ingressConnectionEstablishmentBurstCapacitySecs, |
| 105 | + ) |
| 106 | + admin_db.command( |
| 107 | + setParameter: 1, |
| 108 | + ingressConnectionEstablishmentMaxQueueDepth: @prev_ingressConnectionEstablishmentMaxQueueDepth, |
| 109 | + ) |
| 110 | + else |
| 111 | + # Fallback: at least disable the limiter if previous values were not captured. |
| 112 | + admin_db.command( |
| 113 | + setParameter: 1, |
| 114 | + ingressConnectionEstablishmentRateLimiterEnabled: false, |
| 115 | + ) |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + it 'generates checkout failures when the ingress connection rate limiter is active' do |
| 120 | + admin_db = root_authorized_client.use('admin').database |
| 121 | + |
| 122 | + # Capture current ingress connection establishment parameters so they can be restored. |
| 123 | + current_params = admin_db.command( |
| 124 | + getParameter: 1, |
| 125 | + ingressConnectionEstablishmentRateLimiterEnabled: 1, |
| 126 | + ingressConnectionEstablishmentRatePerSec: 1, |
| 127 | + ingressConnectionEstablishmentBurstCapacitySecs: 1, |
| 128 | + ingressConnectionEstablishmentMaxQueueDepth: 1, |
| 129 | + ).first |
| 130 | + |
| 131 | + @prev_ingressConnectionEstablishmentRateLimiterEnabled = |
| 132 | + current_params['ingressConnectionEstablishmentRateLimiterEnabled'] |
| 133 | + @prev_ingressConnectionEstablishmentRatePerSec = |
| 134 | + current_params['ingressConnectionEstablishmentRatePerSec'] |
| 135 | + @prev_ingressConnectionEstablishmentBurstCapacitySecs = |
| 136 | + current_params['ingressConnectionEstablishmentBurstCapacitySecs'] |
| 137 | + @prev_ingressConnectionEstablishmentMaxQueueDepth = |
| 138 | + current_params['ingressConnectionEstablishmentMaxQueueDepth'] |
| 139 | + |
| 140 | + # Enable the ingress rate limiter with test-specific values. |
| 141 | + admin_db.command( |
| 142 | + setParameter: 1, |
| 143 | + ingressConnectionEstablishmentRateLimiterEnabled: true, |
| 144 | + ) |
| 145 | + admin_db.command( |
| 146 | + setParameter: 1, |
| 147 | + ingressConnectionEstablishmentRatePerSec: 20, |
| 148 | + ) |
| 149 | + admin_db.command( |
| 150 | + setParameter: 1, |
| 151 | + ingressConnectionEstablishmentBurstCapacitySecs: 1, |
| 152 | + ) |
| 153 | + admin_db.command( |
| 154 | + setParameter: 1, |
| 155 | + ingressConnectionEstablishmentMaxQueueDepth: 1, |
| 156 | + ) |
| 157 | + |
| 158 | + # Add a document so $where has something to process. |
| 159 | + client.use('test')['test'].delete_many |
| 160 | + client.use('test')['test'].insert_one({}) |
| 161 | + |
| 162 | + # Run 100 parallel find_one operations that contend for connections. |
| 163 | + threads = 100.times.map do |
| 164 | + Thread.new do |
| 165 | + begin |
| 166 | + client.use('test')['test'].find( |
| 167 | + '$where' => 'function() { sleep(2000); return true; }' |
| 168 | + ).first |
| 169 | + rescue StandardError |
| 170 | + # Ignore connection errors (including checkout timeouts). |
| 171 | + end |
| 172 | + end |
| 173 | + end |
| 174 | + threads.each(&:join) |
| 175 | + |
| 176 | + checkout_failed = subscriber.select_published_events( |
| 177 | + Mongo::Monitoring::Event::Cmap::ConnectionCheckOutFailed |
| 178 | + ) |
| 179 | + |
| 180 | + expect(checkout_failed.length).to be >= 10 |
| 181 | + end |
| 182 | + end |
67 | 183 | end |
0 commit comments