|
178 | 178 | end |
179 | 179 | end |
180 | 180 |
|
| 181 | + it 'handles SSL error during read operations' do |
| 182 | + with_nil_logger do |
| 183 | + memcached(p, 19_191) do |dc| |
| 184 | + # First set a value so we have something to get |
| 185 | + dc.set('ssl_test_key', 'test_value') |
| 186 | + |
| 187 | + server = dc.send(:ring).server_for_key('ssl_test_key') |
| 188 | + |
| 189 | + # Stub error_on_request! to verify SSLError triggers error handling |
| 190 | + # This confirms the SSL error is caught by the rescue clause |
| 191 | + error_handled = false |
| 192 | + original_error_on_request = server.instance_variable_get(:@connection_manager).method(:error_on_request!) |
| 193 | + |
| 194 | + server.instance_variable_get(:@connection_manager).define_singleton_method(:error_on_request!) do |err| |
| 195 | + error_handled = true if err.is_a?(OpenSSL::SSL::SSLError) |
| 196 | + original_error_on_request.call(err) |
| 197 | + end |
| 198 | + |
| 199 | + ssl_error = OpenSSL::SSL::SSLError.new('SSL_read: unexpected eof while reading') |
| 200 | + |
| 201 | + # Binary protocol uses readfull for reading, meta protocol uses gets |
| 202 | + stub_method = p == :binary ? :readfull : :gets |
| 203 | + server.sock.stub(stub_method, proc { raise ssl_error }) do |
| 204 | + # The operation will retry with a new connection and may succeed |
| 205 | + # What matters is the SSLError is caught, not propagated |
| 206 | + dc.get('ssl_test_key') |
| 207 | + rescue Dalli::NetworkError |
| 208 | + # Expected if retries exhausted |
| 209 | + end |
| 210 | + |
| 211 | + assert error_handled, 'SSLError should trigger error_on_request!' |
| 212 | + end |
| 213 | + end |
| 214 | + end |
| 215 | + |
| 216 | + it 'handles SSL error during pipelined get' do |
| 217 | + with_nil_logger do |
| 218 | + memcached(p, 19_191) do |dc| |
| 219 | + ssl_error = OpenSSL::SSL::SSLError.new('SSL_read: unexpected eof while reading') |
| 220 | + |
| 221 | + dc.send(:ring).server_for_key('abc').sock.stub(:write, proc { raise ssl_error }) do |
| 222 | + assert_empty dc.get_multi(['abc']) |
| 223 | + end |
| 224 | + end |
| 225 | + end |
| 226 | + end |
| 227 | + |
181 | 228 | it 'handles asynchronous Thread#raise' do |
182 | 229 | with_nil_logger do |
183 | 230 | memcached(p, 19_191) do |dc| |
|
0 commit comments