mongo 2.11.0 → 2.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +24 -0
  5. data/lib/mongo/address.rb +53 -37
  6. data/lib/mongo/auth.rb +30 -10
  7. data/lib/mongo/auth/cr.rb +1 -0
  8. data/lib/mongo/auth/cr/conversation.rb +13 -13
  9. data/lib/mongo/auth/ldap.rb +2 -1
  10. data/lib/mongo/auth/ldap/conversation.rb +9 -12
  11. data/lib/mongo/auth/scram.rb +1 -0
  12. data/lib/mongo/auth/scram/conversation.rb +36 -27
  13. data/lib/mongo/auth/user.rb +7 -1
  14. data/lib/mongo/auth/x509.rb +2 -1
  15. data/lib/mongo/auth/x509/conversation.rb +9 -9
  16. data/lib/mongo/bulk_write/transformable.rb +3 -3
  17. data/lib/mongo/client.rb +17 -6
  18. data/lib/mongo/cluster.rb +67 -49
  19. data/lib/mongo/cluster/sdam_flow.rb +87 -3
  20. data/lib/mongo/collection/view/readable.rb +3 -1
  21. data/lib/mongo/collection/view/writable.rb +3 -3
  22. data/lib/mongo/cursor/builder/kill_cursors_command.rb +8 -1
  23. data/lib/mongo/cursor/builder/op_kill_cursors.rb +8 -1
  24. data/lib/mongo/database.rb +1 -1
  25. data/lib/mongo/grid/file.rb +5 -0
  26. data/lib/mongo/grid/file/chunk.rb +2 -0
  27. data/lib/mongo/grid/fs_bucket.rb +15 -13
  28. data/lib/mongo/grid/stream/write.rb +9 -3
  29. data/lib/mongo/protocol/serializers.rb +12 -2
  30. data/lib/mongo/retryable.rb +33 -8
  31. data/lib/mongo/server.rb +13 -6
  32. data/lib/mongo/server/connection.rb +15 -8
  33. data/lib/mongo/server/connection_base.rb +7 -4
  34. data/lib/mongo/server/description.rb +34 -21
  35. data/lib/mongo/server/monitor.rb +1 -1
  36. data/lib/mongo/server/monitor/connection.rb +2 -3
  37. data/lib/mongo/session.rb +10 -10
  38. data/lib/mongo/socket.rb +10 -1
  39. data/lib/mongo/uri.rb +1 -1
  40. data/lib/mongo/version.rb +1 -1
  41. data/mongo.gemspec +1 -1
  42. data/spec/README.md +13 -0
  43. data/spec/integration/auth_spec.rb +27 -8
  44. data/spec/integration/bson_symbol_spec.rb +34 -0
  45. data/spec/integration/client_construction_spec.rb +14 -0
  46. data/spec/integration/client_options_spec.rb +5 -5
  47. data/spec/integration/connection_spec.rb +57 -9
  48. data/spec/integration/crud_spec.rb +45 -0
  49. data/spec/integration/cursor_reaping_spec.rb +2 -1
  50. data/spec/integration/grid_fs_bucket_spec.rb +48 -0
  51. data/spec/integration/retryable_errors_spec.rb +204 -39
  52. data/spec/integration/retryable_writes_spec.rb +36 -36
  53. data/spec/integration/size_limit_spec.rb~12e1e9c4f... RUBY-2242 Fix zlib compression (#2021) +98 -0
  54. data/spec/lite_spec_helper.rb +1 -0
  55. data/spec/mongo/address_spec.rb +19 -13
  56. data/spec/mongo/auth/ldap/conversation_spec.rb +1 -1
  57. data/spec/mongo/auth/scram/conversation_spec.rb +25 -14
  58. data/spec/mongo/auth/user/view_spec.rb +36 -1
  59. data/spec/mongo/auth/user_spec.rb +12 -0
  60. data/spec/mongo/auth/x509/conversation_spec.rb +1 -1
  61. data/spec/mongo/bulk_write_spec.rb +2 -2
  62. data/spec/mongo/client_construction_spec.rb +1 -21
  63. data/spec/mongo/cluster_spec.rb +57 -0
  64. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  65. data/spec/mongo/collection_spec.rb +26 -2
  66. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +56 -0
  67. data/spec/mongo/server/connection_spec.rb +76 -8
  68. data/spec/mongo/server/monitor/connection_spec.rb +14 -7
  69. data/spec/mongo/socket/ssl_spec.rb +132 -98
  70. data/spec/mongo/socket/tcp_spec.rb +1 -9
  71. data/spec/mongo/uri_spec.rb +1 -1
  72. data/spec/runners/sdam/verifier.rb +91 -0
  73. data/spec/spec_tests/data/sdam/rs/primary_address_change.yml +29 -0
  74. data/spec/spec_tests/data/sdam/rs/primary_mismatched_me.yml +27 -23
  75. data/spec/spec_tests/data/sdam/rs/primary_to_no_primary_mismatched_me.yml +56 -79
  76. data/spec/spec_tests/data/sdam/sharded/primary_address_change.yml +21 -0
  77. data/spec/spec_tests/data/sdam/sharded/primary_mismatched_me.yml +22 -0
  78. data/spec/spec_tests/data/sdam/single/primary_address_change.yml +24 -0
  79. data/spec/spec_tests/data/sdam/single/primary_mismatched_me.yml +25 -0
  80. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_me_mismatch.yml +159 -0
  81. data/spec/spec_tests/data/sdam_monitoring/{replica_set_other_seed.yml → replica_set_with_primary_change.yml} +97 -101
  82. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary_removal.yml +22 -18
  83. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +90 -0
  84. data/spec/spec_tests/sdam_monitoring_spec.rb +9 -4
  85. data/spec/support/cluster_config.rb +36 -0
  86. data/spec/support/cluster_tools.rb +5 -3
  87. data/spec/support/command_monitoring.rb +1 -1
  88. data/spec/support/constraints.rb +18 -18
  89. data/spec/support/lite_constraints.rb +8 -0
  90. data/spec/support/sdam_monitoring.rb +0 -115
  91. data/spec/support/server_discovery_and_monitoring.rb +2 -0
  92. data/spec/support/spec_config.rb +1 -1
  93. data/spec/support/utils.rb +11 -1
  94. metadata +687 -659
  95. metadata.gz.sig +3 -2
@@ -185,7 +185,9 @@ module Mongo
185
185
  pipeline << { :'$limit' => opts[:limit] } if opts[:limit]
186
186
  pipeline << { :'$group' => { _id: 1, n: { :'$sum' => 1 } } }
187
187
 
188
- opts.select! { |k, _| [:hint, :max_time_ms, :read, :collation, :session].include?(k) }
188
+ opts = opts.select { |k, _| [:hint, :max_time_ms, :read, :collation, :session].include?(k) }
189
+ opts[:collation] ||= collation
190
+
189
191
  first = aggregate(pipeline, opts).first
190
192
  return 0 unless first
191
193
  first['n'].to_i
@@ -234,7 +234,7 @@ module Mongo
234
234
  Operation::U => replacement,
235
235
  }
236
236
  if opts[:upsert]
237
- update_doc[:upsert] = true
237
+ update_doc['upsert'] = true
238
238
  end
239
239
  with_session(opts) do |session|
240
240
  write_concern = write_concern_with_session(session)
@@ -281,7 +281,7 @@ module Mongo
281
281
  Operation::MULTI => true,
282
282
  }
283
283
  if opts[:upsert]
284
- update_doc[:upsert] = true
284
+ update_doc['upsert'] = true
285
285
  end
286
286
  with_session(opts) do |session|
287
287
  write_concern = write_concern_with_session(session)
@@ -325,7 +325,7 @@ module Mongo
325
325
  Operation::U => spec,
326
326
  }
327
327
  if opts[:upsert]
328
- update_doc[:upsert] = true
328
+ update_doc['upsert'] = true
329
329
  end
330
330
  with_session(opts) do |session|
331
331
  write_concern = write_concern_with_session(session)
@@ -92,7 +92,14 @@ module Mongo
92
92
  #
93
93
  # @since 2.3.0
94
94
  def get_cursors_list(spec)
95
- spec[:selector][:cursors].map(&:value)
95
+ spec[:selector][:cursors].map do |value|
96
+ if value.respond_to?(:value)
97
+ # bson-ruby >= 4.6.0
98
+ value = value.value
99
+ else
100
+ value = value.instance_variable_get('@integer')
101
+ end
102
+ end
96
103
  end
97
104
  end
98
105
  end
@@ -87,7 +87,14 @@ module Mongo
87
87
  #
88
88
  # @since 2.3.0
89
89
  def get_cursors_list(spec)
90
- spec[:cursor_ids].map(&:value)
90
+ spec[:cursor_ids].map do |value|
91
+ if value.respond_to?(:value)
92
+ # bson-ruby >= 4.6.0
93
+ value.value
94
+ else
95
+ value.instance_variable_get('@integer')
96
+ end
97
+ end
91
98
  end
92
99
  end
93
100
  end
@@ -157,7 +157,7 @@ module Mongo
157
157
  # @option opts :read [ Hash ] The read preference for this command.
158
158
  # @option opts :session [ Session ] The session to use for this command.
159
159
  #
160
- # @return [ Hash ] The result of the command execution.
160
+ # @return [ Mongo::Operation::Result ] The result of the command execution.
161
161
  def command(operation, opts = {})
162
162
  txn_read_pref = if opts[:session] && opts[:session].in_transaction?
163
163
  opts[:session].txn_read_preference
@@ -104,6 +104,11 @@ module Mongo
104
104
  # chunk objects and assemble the data. If we have an IO object, then
105
105
  # it's the original file data and we must split it into chunks and set
106
106
  # the original data itself.
107
+ #
108
+ # @param [ IO, String, Array<BSON::Document> ] value The file object,
109
+ # file contents or chunk documents.
110
+ #
111
+ # @return [ Array<Grid::File::Chunk> ] Array of chunks.
107
112
  def initialize_chunks!(value)
108
113
  if value.is_a?(Array)
109
114
  @chunks = value.map{ |doc| Chunk.new(doc) }
@@ -151,6 +151,7 @@ module Mongo
151
151
  # @return [ String ] The assembled data.
152
152
  #
153
153
  # @since 2.0.0
154
+ # @api private
154
155
  def assemble(chunks)
155
156
  chunks.reduce(''){ |data, chunk| data << chunk.data.data }
156
157
  end
@@ -167,6 +168,7 @@ module Mongo
167
168
  # @return [ Array<Chunk> ] The chunks of the data.
168
169
  #
169
170
  # @since 2.0.0
171
+ # @api private
170
172
  def split(io, file_info, offset = 0)
171
173
  io = StringIO.new(io) if io.is_a?(String)
172
174
  parts = Enumerator.new { |y| y << io.read(file_info.chunk_size) until io.eof? }
@@ -177,7 +177,7 @@ module Mongo
177
177
  #
178
178
  # @since 2.0.0
179
179
  def prefix
180
- @options[:fs_name] || @options[:bucket_name]|| DEFAULT_ROOT
180
+ @options[:fs_name] || @options[:bucket_name] || DEFAULT_ROOT
181
181
  end
182
182
 
183
183
  # Remove a single file from the GridFS.
@@ -230,7 +230,8 @@ module Mongo
230
230
  #
231
231
  # @since 2.1.0
232
232
  def open_download_stream(id, options = nil)
233
- read_stream(id, options).tap do |stream|
233
+ options = Hash[(options || {}).map { |k, v| [k.to_sym, v] }]
234
+ read_stream(id, **options).tap do |stream|
234
235
  if block_given?
235
236
  begin
236
237
  yield stream
@@ -348,15 +349,15 @@ module Mongo
348
349
  download_to_stream(open_download_stream_by_name(filename, opts).file_id, io)
349
350
  end
350
351
 
351
- # Opens an upload stream to GridFS to which the contents of a user file came be written.
352
+ # Opens an upload stream to GridFS to which the contents of a file or
353
+ # blob can be written.
352
354
  #
353
- # @example Open a stream to which the contents of a file came be written.
354
- # fs.open_upload_stream('a-file.txt')
355
- #
356
- # @param [ String ] filename The filename of the file to upload.
355
+ # @param [ String ] filename The name of the file in GridFS.
357
356
  # @param [ Hash ] opts The options for the write stream.
358
357
  #
359
- # @option opts [ Object ] :file_id An optional unique file id. An ObjectId is generated otherwise.
358
+ # @option opts [ Object ] :file_id An optional unique file id.
359
+ # A BSON::ObjectId is automatically generated if a file id is not
360
+ # provided.
360
361
  # @option opts [ Integer ] :chunk_size Override the default chunk size.
361
362
  # @option opts [ Hash ] :metadata User data for the 'metadata' field of the files
362
363
  # collection document.
@@ -375,7 +376,8 @@ module Mongo
375
376
  #
376
377
  # @since 2.1.0
377
378
  def open_upload_stream(filename, opts = {})
378
- write_stream(filename, opts).tap do |stream|
379
+ opts = Hash[opts.map { |k, v| [k.to_sym, v] }]
380
+ write_stream(filename, **opts).tap do |stream|
379
381
  if block_given?
380
382
  begin
381
383
  yield stream
@@ -462,12 +464,12 @@ module Mongo
462
464
  #
463
465
  # @option opts [ BSON::Document ] :file_info_doc For internal
464
466
  # driver use only. A BSON document to use as file information.
465
- def read_stream(id, opts = nil)
466
- Stream.get(self, Stream::READ_MODE, { file_id: id }.update(options).update(opts || {}))
467
+ def read_stream(id, **opts)
468
+ Stream.get(self, Stream::READ_MODE, { file_id: id }.update(options).update(opts))
467
469
  end
468
470
 
469
- def write_stream(filename, opts)
470
- Stream.get(self, Stream::WRITE_MODE, { filename: filename }.merge!(options).merge!(opts))
471
+ def write_stream(filename, **opts)
472
+ Stream.get(self, Stream::WRITE_MODE, { filename: filename }.update(options).update(opts))
471
473
  end
472
474
 
473
475
  def chunks_name
@@ -82,12 +82,12 @@ module Mongo
82
82
  @open = true
83
83
  end
84
84
 
85
- # Write to the GridFS bucket from the source stream.
85
+ # Write to the GridFS bucket from the source stream or a string.
86
86
  #
87
87
  # @example Write to GridFS.
88
88
  # stream.write(io)
89
89
  #
90
- # @param [ IO ] io The source io stream to upload from.
90
+ # @param [ String | IO ] io The string or IO object to upload from.
91
91
  #
92
92
  # @return [ Stream::Write ] self The write stream itself.
93
93
  #
@@ -95,7 +95,13 @@ module Mongo
95
95
  def write(io)
96
96
  ensure_open!
97
97
  @indexes ||= ensure_indexes!
98
- @length += io.size
98
+ @length += if io.respond_to?(:bytesize)
99
+ # String objects
100
+ io.bytesize
101
+ else
102
+ # IO objects
103
+ io.size
104
+ end
99
105
  chunks = File::Chunk.split(io, file_info, @n)
100
106
  @n += chunks.size
101
107
  chunks_collection.insert_many(chunks) unless chunks.empty?
@@ -110,7 +110,12 @@ module Mongo
110
110
  # @return [String] Buffer with serialized value.
111
111
  def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
112
112
  if value.is_a?(BSON::Int32)
113
- value = value.value
113
+ if value.respond_to?(:value)
114
+ # bson-ruby >= 4.6.0
115
+ value = value.value
116
+ else
117
+ value = value.instance_variable_get('@integer')
118
+ end
114
119
  end
115
120
  buffer.put_int32(value)
116
121
  end
@@ -138,7 +143,12 @@ module Mongo
138
143
  # @return [ String ] Buffer with serialized value.
139
144
  def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
140
145
  if value.is_a?(BSON::Int64)
141
- value = value.value
146
+ if value.respond_to?(:value)
147
+ # bson-ruby >= 4.6.0
148
+ value = value.value
149
+ else
150
+ value = value.instance_variable_get('@integer')
151
+ end
142
152
  end
143
153
  buffer.put_int64(value)
144
154
  end
@@ -119,7 +119,12 @@ module Mongo
119
119
  legacy_read_with_retry(session, server_selector, &block)
120
120
  else
121
121
  server = select_server(cluster, server_selector, session)
122
- yield server
122
+ begin
123
+ yield server
124
+ rescue Error::SocketError, Error::SocketTimeoutError, Error::OperationFailure => e
125
+ e.add_note('retries disabled')
126
+ raise e
127
+ end
123
128
  end
124
129
  end
125
130
 
@@ -214,12 +219,14 @@ module Mongo
214
219
  begin
215
220
  yield(server, txn_num, false)
216
221
  rescue Error::SocketError, Error::SocketTimeoutError => e
222
+ e.add_note('modern retry')
217
223
  e.add_note("attempt 1")
218
224
  if session.in_transaction? && !ending_transaction
219
225
  raise e
220
226
  end
221
227
  retry_write(e, session, txn_num, &block)
222
228
  rescue Error::OperationFailure => e
229
+ e.add_note('modern retry')
223
230
  e.add_note("attempt 1")
224
231
  if e.unsupported_retryable_write?
225
232
  raise_unsupported_error(e)
@@ -250,7 +257,12 @@ module Mongo
250
257
  def nro_write_with_retry(session, write_concern, &block)
251
258
  if session && session.client.options[:retry_writes]
252
259
  server = select_server(cluster, ServerSelector.primary, session)
253
- yield server
260
+ begin
261
+ yield server
262
+ rescue Error::SocketError, Error::SocketTimeoutError, Error::OperationFailure => e
263
+ e.add_note('retries disabled')
264
+ raise e
265
+ end
254
266
  else
255
267
  legacy_write_with_retry(nil, session, &block)
256
268
  end
@@ -280,7 +292,8 @@ module Mongo
280
292
  server ||= select_server(cluster, ServerSelector.primary, session)
281
293
  yield server
282
294
  rescue Error::OperationFailure => e
283
- e.add_note("attempt #{attempt + 1}")
295
+ e.add_note('legacy retry')
296
+ e.add_note("attempt #{attempt}")
284
297
  server = nil
285
298
  if attempt > client.max_write_retries
286
299
  raise e
@@ -298,18 +311,19 @@ module Mongo
298
311
  private
299
312
 
300
313
  def modern_read_with_retry(session, server_selector, &block)
301
- attempt = 0
302
314
  server = select_server(cluster, server_selector, session)
303
315
  begin
304
316
  yield server
305
317
  rescue Error::SocketError, Error::SocketTimeoutError => e
306
- e.add_note("attempt #{attempt + 1}")
318
+ e.add_note('modern retry')
319
+ e.add_note("attempt 1")
307
320
  if session.in_transaction?
308
321
  raise e
309
322
  end
310
323
  retry_read(e, server_selector, session, &block)
311
324
  rescue Error::OperationFailure => e
312
- e.add_note("attempt #{attempt + 1}")
325
+ e.add_note('modern retry')
326
+ e.add_note("attempt 1")
313
327
  if session.in_transaction? || !e.write_retryable?
314
328
  raise e
315
329
  end
@@ -324,7 +338,8 @@ module Mongo
324
338
  attempt += 1
325
339
  yield server
326
340
  rescue Error::SocketError, Error::SocketTimeoutError => e
327
- e.add_note("attempt #{attempt + 1}")
341
+ e.add_note('legacy retry')
342
+ e.add_note("attempt #{attempt}")
328
343
  if attempt > client.max_read_retries || (session && session.in_transaction?)
329
344
  raise e
330
345
  end
@@ -332,7 +347,8 @@ module Mongo
332
347
  server = select_server(cluster, server_selector, session)
333
348
  retry
334
349
  rescue Error::OperationFailure => e
335
- e.add_note("attempt #{attempt + 1}")
350
+ e.add_note('legacy retry')
351
+ e.add_note("attempt #{attempt}")
336
352
  if e.retryable? && !(session && session.in_transaction?)
337
353
  if attempt > client.max_read_retries
338
354
  raise e
@@ -375,9 +391,11 @@ module Mongo
375
391
  begin
376
392
  yield server, true
377
393
  rescue Error::SocketError, Error::SocketTimeoutError => e
394
+ e.add_note('modern retry')
378
395
  e.add_note("attempt 2")
379
396
  raise e
380
397
  rescue Error::OperationFailure => e
398
+ e.add_note('modern retry')
381
399
  unless e.write_retryable?
382
400
  original_error.add_note("later retry failed: #{e.class}: #{e}")
383
401
  raise original_error
@@ -385,6 +403,7 @@ module Mongo
385
403
  e.add_note("attempt 2")
386
404
  raise e
387
405
  rescue => e
406
+ e.add_note('modern retry')
388
407
  original_error.add_note("later retry failed: #{e.class}: #{e}")
389
408
  raise original_error
390
409
  end
@@ -398,15 +417,19 @@ module Mongo
398
417
  # server unknown). Here we just need to wait for server selection.
399
418
  server = select_server(cluster, ServerSelector.primary, session)
400
419
  unless server.retry_writes?
420
+ # Do not need to add "modern retry" here, it should already be on
421
+ # the first exception.
401
422
  original_error.add_note('did not retry because server selected for retry does not supoprt retryable writes')
402
423
  raise original_error
403
424
  end
404
425
  log_retry(original_error, message: 'Write retry')
405
426
  yield(server, txn_num, true)
406
427
  rescue Error::SocketError, Error::SocketTimeoutError => e
428
+ e.add_note('modern retry')
407
429
  e.add_note('attempt 2')
408
430
  raise e
409
431
  rescue Error::OperationFailure => e
432
+ e.add_note('modern retry')
410
433
  if e.write_retryable?
411
434
  e.add_note('attempt 2')
412
435
  raise e
@@ -415,6 +438,8 @@ module Mongo
415
438
  raise original_error
416
439
  end
417
440
  rescue => e
441
+ # Do not need to add "modern retry" here, it should already be on
442
+ # the first exception.
418
443
  original_error.add_note("later retry failed: #{e.class}: #{e}")
419
444
  raise original_error
420
445
  end
@@ -306,12 +306,11 @@ module Mongo
306
306
  "#<Mongo::Server:0x#{object_id} address=#{address.host}:#{address.port}>"
307
307
  end
308
308
 
309
- # @note This method is experimental and subject to change.
309
+ # @return [ String ] String representing server status (e.g. PRIMARY).
310
310
  #
311
- # @api experimental
312
- # @since 2.7.0
313
- def summary
314
- status = case
311
+ # @api private
312
+ def status
313
+ case
315
314
  when primary?
316
315
  'PRIMARY'
317
316
  when secondary?
@@ -331,8 +330,16 @@ module Mongo
331
330
  else
332
331
  # Since the summary method is often used for debugging, do not raise
333
332
  # an exception in case none of the expected types matched
334
- ''
333
+ nil
335
334
  end
335
+ end
336
+
337
+ # @note This method is experimental and subject to change.
338
+ #
339
+ # @api experimental
340
+ # @since 2.7.0
341
+ def summary
342
+ status = self.status || ''
336
343
  if replica_set_name
337
344
  status += " replica_set=#{replica_set_name}"
338
345
  end
@@ -103,6 +103,12 @@ module Mongo
103
103
  )
104
104
  end
105
105
 
106
+ # @return [ Server::Description ] The server description obtained from
107
+ # the handshake on this connection.
108
+ #
109
+ # @api private
110
+ attr_reader :description
111
+
106
112
  # @return [ Time ] The last time the connection was checked back into a pool.
107
113
  #
108
114
  # @since 2.5.0
@@ -181,13 +187,14 @@ module Mongo
181
187
 
182
188
  # Separate method to permit easier mocking in the test suite.
183
189
  def do_connect
184
- socket = address.socket(socket_timeout, ssl_options,
185
- connect_timeout: address.connect_timeout)
190
+ socket = address.socket(socket_timeout, ssl_options, address.options)
186
191
 
187
192
  begin
188
193
  handshake!(socket)
189
- pending_connection = PendingConnection.new(socket, @server, monitoring, options.merge(id: id))
190
- authenticate!(pending_connection)
194
+ unless description.arbiter?
195
+ pending_connection = PendingConnection.new(socket, @server, monitoring, options.merge(id: id))
196
+ authenticate!(pending_connection)
197
+ end
191
198
  rescue Exception
192
199
  socket.close
193
200
  raise
@@ -314,7 +321,7 @@ module Mongo
314
321
  raise exc
315
322
  end
316
323
  rescue => e
317
- log_warn("Failed to handshake with #{address}: #{e.class}: #{e}")
324
+ log_warn("Failed to handshake with #{address}: #{e.class}: #{e}:\n#{e.backtrace[0..5].join("\n")}")
318
325
  raise
319
326
  end
320
327
  end
@@ -356,8 +363,8 @@ module Mongo
356
363
  @auth_mechanism = nil
357
364
  end
358
365
 
359
- new_description = Description.new(address, response, average_rtt)
360
- @server.cluster.run_sdam_flow(@server.description, new_description)
366
+ @description = Description.new(address, response, average_rtt)
367
+ @server.cluster.run_sdam_flow(@server.description, @description)
361
368
  end
362
369
 
363
370
  def authenticate!(pending_connection)
@@ -371,7 +378,7 @@ module Mongo
371
378
  begin
372
379
  Auth.get(user).login(pending_connection)
373
380
  rescue => e
374
- log_warn("Failed to handshake with #{address}: #{e.class}: #{e}")
381
+ log_warn("Failed to handshake with #{address}: #{e.class}: #{e}:\n#{e.backtrace[0..5].join("\n")}")
375
382
  raise
376
383
  end
377
384
  end