mongo 2.2.0 → 2.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b03a2e7ce5246f9d38690f731f53d29a5469d30
4
- data.tar.gz: aaca95e6f570d466155c87d4c549a4f3c5bc0341
3
+ metadata.gz: 70bb36aedc302fa28a3103c1216e865448733b54
4
+ data.tar.gz: 05f39ba3e498bd4763f89ca4ac7b30d9d5b3537f
5
5
  SHA512:
6
- metadata.gz: f6fa180a5c94bcb5d7a809d170c8ec12ec28d0d6035575ef0cc677b9f4c68ec81c26411948f071945b2b2d829b192e0312f29416d2c3a589830c5ee40f90b133
7
- data.tar.gz: fce85899375de257592434225cd1db4e3d3971e8b85b6ec111ef30c967e0fa0e817569b843dc0f3c342d7e58749c259a8111cc2b9d741ef321dc335a1ad08bab
6
+ metadata.gz: 704bcf79dd037eeb329fd5e9120d9ead72b80f8bf4897e9260e2b624afad5c280feb0300228cee83b8ff639f97ef288e9dcf4ea7d6aa86b519e2e6f15853e688
7
+ data.tar.gz: c25ecaaee43f90ee59c501712aa8632802a31136deebc90cebaa6bb31ba419be5ba44ad9ad5f5f1c721bf36c722c6828e65bf340fdf34b41f967a91f0414e7bd
Binary file
@@ -15,6 +15,7 @@
15
15
  require 'forwardable'
16
16
  require 'bson'
17
17
  require 'openssl'
18
+ require 'mongo/bson'
18
19
  require 'mongo/options'
19
20
  require 'mongo/loggable'
20
21
  require 'mongo/monitoring'
@@ -0,0 +1,32 @@
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Patch for allowing deprecated symbols to be used.
16
+ #
17
+ # @since 2.2.1
18
+ class Symbol
19
+
20
+ # Overrides the default BSON type to use the symbol type instead of a
21
+ # string type.
22
+ #
23
+ # @example Get the bson type.
24
+ # :test.bson_type
25
+ #
26
+ # @return [ String ] The charater 14.
27
+ #
28
+ # @since 2.2.1
29
+ def bson_type
30
+ BSON::Symbol::BSON_TYPE
31
+ end
32
+ end
@@ -33,9 +33,11 @@ module Mongo
33
33
  class Cursor
34
34
  extend Forwardable
35
35
  include Enumerable
36
+ include Retryable
36
37
 
37
38
  def_delegators :@view, :collection, :limit
38
39
  def_delegators :collection, :client, :database
40
+ def_delegators :@server, :cluster
39
41
 
40
42
  # @return [ Collection::View ] view The collection view.
41
43
  attr_reader :view
@@ -157,7 +159,9 @@ module Mongo
157
159
  end
158
160
 
159
161
  def get_more
160
- process(get_more_operation.execute(@server.context))
162
+ read_with_retry do
163
+ process(get_more_operation.execute(@server.context))
164
+ end
161
165
  end
162
166
 
163
167
  def get_more_operation
@@ -169,7 +173,9 @@ module Mongo
169
173
  end
170
174
 
171
175
  def kill_cursors
172
- kill_cursors_operation.execute(@server.context)
176
+ read_with_retry do
177
+ kill_cursors_operation.execute(@server.context)
178
+ end
173
179
  end
174
180
 
175
181
  def kill_cursors_operation
@@ -32,10 +32,12 @@ module Mongo
32
32
  "can't connect",
33
33
  'no master',
34
34
  'not master',
35
+ 'could not contact primary',
35
36
  'connect failed',
36
37
  'error querying',
37
38
  'could not get last error',
38
- 'connection attempt failed'
39
+ 'connection attempt failed',
40
+ 'interrupted at shutdown'
39
41
  ].freeze
40
42
 
41
43
  # Can the operation that caused the error be retried?
@@ -67,6 +67,11 @@ module Mongo
67
67
  # @since 2.2.0
68
68
  Q = 'q'.freeze
69
69
 
70
+ # Default max message size of 48MB.
71
+ #
72
+ # @since 2.2.1
73
+ MAX_MESSAGE_SIZE = 50331648.freeze
74
+
70
75
  # Returns the request id for the message
71
76
  #
72
77
  # @return [Fixnum] The request id for this message
@@ -100,10 +105,19 @@ module Mongo
100
105
 
101
106
  # Deserializes messages from an IO stream
102
107
  #
103
- # @param io [IO] Stream containing a message
104
- # @return [Message] Instance of a Message class
105
- def self.deserialize(io)
108
+ # @param [ Integer ] max_message_size The max message size.
109
+ # @param [ IO ] io Stream containing a message
110
+ #
111
+ # @return [ Message ] Instance of a Message class
112
+ def self.deserialize(io, max_message_size = MAX_MESSAGE_SIZE)
106
113
  length = deserialize_header(BSON::ByteBuffer.new(io.read(16))).first
114
+
115
+ # Protection from potential DOS man-in-the-middle attacks. See
116
+ # DRIVERS-276.
117
+ if length > max_message_size
118
+ raise Error::MaxMessageSize.new(max_message_size)
119
+ end
120
+
107
121
  buffer = BSON::ByteBuffer.new(io.read(length - 16))
108
122
  message = allocate
109
123
  fields.each do |field|
@@ -24,6 +24,11 @@ module Mongo
24
24
  # @since 2.1.0
25
25
  NOT_MASTER = 'not master'.freeze
26
26
 
27
+ # Could not contact primary error message, seen on stepdowns
28
+ #
29
+ # @since 2.2.0
30
+ COULD_NOT_CONTACT_PRIMARY = 'could not contact primary'.freeze
31
+
27
32
  # Execute a read operation with a retry.
28
33
  #
29
34
  # @api private
@@ -83,7 +88,7 @@ module Mongo
83
88
  begin
84
89
  block.call
85
90
  rescue Error::OperationFailure => e
86
- if e.message.include?(NOT_MASTER)
91
+ if e.message.include?(NOT_MASTER) || e.message.include?(COULD_NOT_CONTACT_PRIMARY)
87
92
  retry_operation(&block)
88
93
  else
89
94
  raise e
@@ -104,7 +104,7 @@ module Mongo
104
104
 
105
105
  def read
106
106
  ensure_connected do |socket|
107
- Protocol::Reply.deserialize(socket)
107
+ Protocol::Reply.deserialize(socket, max_message_size)
108
108
  end
109
109
  end
110
110
  end
@@ -168,7 +168,7 @@ module Mongo
168
168
  def ping
169
169
  ensure_connected do |socket|
170
170
  socket.write(PING_BYTES)
171
- reply = Protocol::Reply.deserialize(socket)
171
+ reply = Protocol::Reply.deserialize(socket, max_message_size)
172
172
  reply.documents[0][Operation::Result::OK] == 1
173
173
  end
174
174
  end
@@ -57,18 +57,6 @@ module Mongo
57
57
  end
58
58
  end
59
59
 
60
- # Get the connection timeout.
61
- #
62
- # @example Get the connection timeout.
63
- # connection.timeout
64
- #
65
- # @return [ Float ] The connection timeout in seconds.
66
- #
67
- # @since 2.0.0
68
- def timeout
69
- @timeout ||= options[:connect_timeout] || CONNECT_TIMEOUT
70
- end
71
-
72
60
  # Tell the underlying socket to establish a connection to the host.
73
61
  #
74
62
  # @example Connect to the host.
@@ -128,6 +116,18 @@ module Mongo
128
116
  @socket = nil
129
117
  @pid = Process.pid
130
118
  end
119
+
120
+ # Get the connection timeout.
121
+ #
122
+ # @example Get the connection timeout.
123
+ # connection.timeout
124
+ #
125
+ # @return [ Float ] The connection timeout in seconds.
126
+ #
127
+ # @since 2.0.0
128
+ def timeout
129
+ @timeout ||= options[:connect_timeout] || CONNECT_TIMEOUT
130
+ end
131
131
  end
132
132
  end
133
133
  end
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.2.0'.freeze
20
+ VERSION = '2.2.1'.freeze
21
21
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbol do
4
+
5
+ describe '#bson_type' do
6
+
7
+ it 'serializes to a symbol type' do
8
+ expect(:test.bson_type).to eq(14.chr)
9
+ end
10
+ end
11
+ end
@@ -61,13 +61,35 @@ describe Mongo::Cursor do
61
61
  authorized_collection.delete_many
62
62
  end
63
63
 
64
- it 'returns the correct amount' do
65
- expect(cursor.to_a.count).to eq(102)
64
+ context 'when a getmore gets a socket error' do
65
+
66
+ let(:op) do
67
+ double('operation')
68
+ end
69
+
70
+ before do
71
+ expect(cursor).to receive(:get_more_operation).and_return(op).ordered
72
+ expect(op).to receive(:execute).and_raise(Mongo::Error::SocketError).ordered
73
+ expect(cursor).to receive(:get_more_operation).and_call_original.ordered
74
+ end
75
+
76
+ it 'iterates the documents' do
77
+ cursor.each do |doc|
78
+ expect(doc).to have_key('field')
79
+ end
80
+ end
66
81
  end
67
82
 
68
- it 'iterates the documents' do
69
- cursor.each do |doc|
70
- expect(doc).to have_key('field')
83
+ context 'when no errors occur' do
84
+
85
+ it 'returns the correct amount' do
86
+ expect(cursor.to_a.count).to eq(102)
87
+ end
88
+
89
+ it 'iterates the documents' do
90
+ cursor.each do |doc|
91
+ expect(doc).to have_key('field')
92
+ end
71
93
  end
72
94
  end
73
95
  end
@@ -86,6 +86,17 @@ describe Mongo::Protocol::Reply do
86
86
 
87
87
  describe '#deserialize' do
88
88
 
89
+ context 'when the message size is greater than the max message size' do
90
+
91
+ let(:length) { Mongo::Protocol::Message::MAX_MESSAGE_SIZE + 1 }
92
+
93
+ it 'raises a max message size error' do
94
+ expect {
95
+ reply
96
+ }.to raise_error(Mongo::Error::MaxMessageSize)
97
+ end
98
+ end
99
+
89
100
  describe 'response flags' do
90
101
 
91
102
  context 'no flags' do
@@ -150,7 +150,7 @@ module Mongo
150
150
  # @since 2.0.0
151
151
  class Outcome
152
152
 
153
- # @return [ Array<Array<String, Hash>>] servers The expecations for
153
+ # @return [ Hash ] servers The expecations for
154
154
  # server states.
155
155
  attr_reader :servers
156
156
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -9,30 +9,8 @@ authors:
9
9
  - Durran Jordan
10
10
  autorequire:
11
11
  bindir: bin
12
- cert_chain:
13
- - |
14
- -----BEGIN CERTIFICATE-----
15
- MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
16
- 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KK1zXzADflsx51jjP5rZJJltnoVsBBgN
32
- EhIn2f8suSc9QAqYt7w4T+PMtjxWTVcXs+Uy2PbDtjhtEBz6ZsP6YSsOpJbrCjCV
33
- wZtXjpRUvWz86V5vjhHCTE8fqfEb85aeDwUCckPzpio=
34
- -----END CERTIFICATE-----
35
- date: 2015-12-07 00:00:00.000000000 Z
12
+ cert_chain: []
13
+ date: 2015-12-16 00:00:00.000000000 Z
36
14
  dependencies:
37
15
  - !ruby/object:Gem::Dependency
38
16
  name: bson
@@ -59,6 +37,7 @@ files:
59
37
  - README.md
60
38
  - Rakefile
61
39
  - bin/mongo_console
40
+ - lib/csasl/csasl.bundle
62
41
  - lib/mongo.rb
63
42
  - lib/mongo/address.rb
64
43
  - lib/mongo/address/ipv4.rb
@@ -76,6 +55,7 @@ files:
76
55
  - lib/mongo/auth/user/view.rb
77
56
  - lib/mongo/auth/x509.rb
78
57
  - lib/mongo/auth/x509/conversation.rb
58
+ - lib/mongo/bson.rb
79
59
  - lib/mongo/bulk_write.rb
80
60
  - lib/mongo/bulk_write/combineable.rb
81
61
  - lib/mongo/bulk_write/ordered_combiner.rb
@@ -304,6 +284,7 @@ files:
304
284
  - spec/mongo/auth/user_spec.rb
305
285
  - spec/mongo/auth/x509_spec.rb
306
286
  - spec/mongo/auth_spec.rb
287
+ - spec/mongo/bson_spec.rb
307
288
  - spec/mongo/bulk_write/ordered_combiner_spec.rb
308
289
  - spec/mongo/bulk_write/unordered_combiner_spec.rb
309
290
  - spec/mongo/bulk_write_spec.rb
@@ -568,7 +549,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
568
549
  version: '0'
569
550
  requirements: []
570
551
  rubyforge_project:
571
- rubygems_version: 2.4.8
552
+ rubygems_version: 2.4.5.1
572
553
  signing_key:
573
554
  specification_version: 4
574
555
  summary: Ruby driver for MongoDB
@@ -586,6 +567,7 @@ test_files:
586
567
  - spec/mongo/auth/user_spec.rb
587
568
  - spec/mongo/auth/x509_spec.rb
588
569
  - spec/mongo/auth_spec.rb
570
+ - spec/mongo/bson_spec.rb
589
571
  - spec/mongo/bulk_write/ordered_combiner_spec.rb
590
572
  - spec/mongo/bulk_write/unordered_combiner_spec.rb
591
573
  - spec/mongo/bulk_write_spec.rb
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file