Skip to content

Commit d99bc98

Browse files
GODRIVER-3054 LB init handshake should always be hello
1 parent 83a49b8 commit d99bc98

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

mongo/integration/handshake_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,9 @@ func TestLoadBalancedConnectionHandshake(t *testing.T) {
215215
messages := mt.GetProxiedMessages()
216216
handshakeMessage := messages[:1][0]
217217

218-
hello := handshake.LegacyHello
219-
if os.Getenv("REQUIRE_API_VERSION") == "true" {
220-
hello = "hello"
221-
}
222-
223-
assert.Equal(mt, hello, handshakeMessage.CommandName)
218+
// Per the specifications, if loadBalanced=true, drivers MUST use the hello
219+
// command for the initial handshake and use the OP_MSG protocol.
220+
assert.Equal(mt, "hello", handshakeMessage.CommandName)
224221
assert.Equal(mt, wiremessage.OpMsg, handshakeMessage.Sent.OpCode)
225222
})
226223

testdata/load-balancers/sdam-error-handling.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@
279279
},
280280
"data": {
281281
"failCommands": [
282-
"isMaster"
282+
"isMaster",
283+
"hello"
283284
],
284285
"closeConnection": true,
285286
"appName": "lbSDAMErrorTestClient"

testdata/load-balancers/sdam-error-handling.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ tests:
153153
configureFailPoint: failCommand
154154
mode: { times: 1 }
155155
data:
156-
failCommands: [isMaster]
156+
failCommands: [isMaster, hello]
157157
closeConnection: true
158158
appName: *singleClientAppName
159159
- name: insertOne

x/mongo/driver/operation/hello.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func (h *Hello) handshakeCommand(dst []byte, desc description.SelectedServer) ([
530530
func (h *Hello) command(dst []byte, desc description.SelectedServer) ([]byte, error) {
531531
// Use "hello" if topology is LoadBalanced, API version is declared or server
532532
// has responded with "helloOk". Otherwise, use legacy hello.
533-
if desc.Kind == description.LoadBalanced || h.serverAPI != nil || desc.Server.HelloOK {
533+
if h.loadBalanced || h.serverAPI != nil || desc.Server.HelloOK {
534534
dst = bsoncore.AppendInt32Element(dst, "hello", 1)
535535
} else {
536536
dst = bsoncore.AppendInt32Element(dst, handshake.LegacyHello, 1)

0 commit comments

Comments
 (0)