Skip to content

Commit 49af6e2

Browse files
authored
GODRIVER-1999 allow directConnection=false in loadBalanced=true URIs (#683)
1 parent 8258033 commit 49af6e2

File tree

7 files changed

+52
-34
lines changed

7 files changed

+52
-34
lines changed

data/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection-errors.json

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

data/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection-errors.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"uri": "mongodb+srv://test20.test.build.10gen.cc/?directConnection=false",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost.test.build.10gen.cc:27017"
8+
],
9+
"options": {
10+
"loadBalanced": true,
11+
"ssl": true,
12+
"directConnection": false
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# The TXT record for test20.test.build.10gen.cc contains loadBalanced=true.
2+
# DRIVERS-1721 introduced this test as passing.
3+
uri: "mongodb+srv://test20.test.build.10gen.cc/?directConnection=false"
4+
seeds:
5+
- localhost.test.build.10gen.cc:27017
6+
hosts:
7+
# In LB mode, the driver does not do server discovery, so the hostname does
8+
# not get resolved to localhost:27017.
9+
- localhost.test.build.10gen.cc:27017
10+
options:
11+
loadBalanced: true
12+
ssl: true
13+
directConnection: false

data/uri-options/connection-options.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@
180180
"loadBalanced": true
181181
}
182182
},
183+
{
184+
"description": "loadBalanced=true with directConnection=false",
185+
"uri": "mongodb://example.com/?loadBalanced=true&directConnection=false",
186+
"valid": true,
187+
"warning": false,
188+
"hosts": null,
189+
"auth": null,
190+
"options": {
191+
"loadBalanced": true,
192+
"directConnection": false
193+
}
194+
},
183195
{
184196
"description": "loadBalanced=false",
185197
"uri": "mongodb://example.com/?loadBalanced=false",
@@ -218,15 +230,6 @@
218230
"auth": null,
219231
"options": {}
220232
},
221-
{
222-
"description": "loadBalanced=true with directConnection=false causes an error",
223-
"uri": "mongodb://example.com/?loadBalanced=true&directConnection=false",
224-
"valid": false,
225-
"warning": false,
226-
"hosts": null,
227-
"auth": null,
228-
"options": {}
229-
},
230233
{
231234
"description": "loadBalanced=true with replicaSet causes an error",
232235
"uri": "mongodb://example.com/?loadBalanced=true&replicaSet=replset",

data/uri-options/connection-options.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ tests:
156156
auth: ~
157157
options:
158158
loadBalanced: true
159+
-
160+
description: loadBalanced=true with directConnection=false
161+
uri: "mongodb://example.com/?loadBalanced=true&directConnection=false"
162+
valid: true
163+
warning: false
164+
hosts: ~
165+
auth: ~
166+
options:
167+
loadBalanced: true
168+
directConnection: false
159169
-
160170
description: loadBalanced=false
161171
uri: "mongodb://example.com/?loadBalanced=false"
@@ -189,14 +199,6 @@ tests:
189199
hosts: ~
190200
auth: ~
191201
options: {}
192-
-
193-
description: loadBalanced=true with directConnection=false causes an error
194-
uri: "mongodb://example.com/?loadBalanced=true&directConnection=false"
195-
valid: false
196-
warning: false
197-
hosts: ~
198-
auth: ~
199-
options: {}
200202
-
201203
description: loadBalanced=true with replicaSet causes an error
202204
uri: "mongodb://example.com/?loadBalanced=true&replicaSet=replset"

x/mongo/driver/connstring/connstring.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ func (p *parser) validate() error {
340340
if p.Scheme == SchemeMongoDBSRV {
341341
return errors.New("a direct connection cannot be made if an SRV URI is used")
342342
}
343+
if p.LoadBalancedSet && p.LoadBalanced {
344+
return internal.ErrLoadBalancedWithDirectConnection
345+
}
343346
}
344347

345348
// Validation for load-balanced mode.
@@ -350,9 +353,6 @@ func (p *parser) validate() error {
350353
if p.ReplicaSet != "" {
351354
return internal.ErrLoadBalancedWithReplicaSet
352355
}
353-
if p.ConnectSet || p.DirectConnectionSet {
354-
return internal.ErrLoadBalancedWithDirectConnection
355-
}
356356
}
357357

358358
return nil

0 commit comments

Comments
 (0)