Skip to content

Commit

Permalink
GODRIVER-3054 Handshake connection should not use legacy for LB
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Nov 28, 2023
1 parent 8705829 commit d77f8cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
13 changes: 4 additions & 9 deletions x/mongo/driver/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1357,14 +1357,6 @@ func (op Operation) createMsgWireMessage(
return bsoncore.UpdateLength(dst, wmindex, int32(len(dst[wmindex:]))), info, nil
}

// isLegacyHandshake returns True if the operation is the first message of
// the initial handshake and should use a legacy hello.
func isLegacyHandshake(op Operation, desc description.SelectedServer) bool {
isInitialHandshake := desc.WireVersion == nil || desc.WireVersion.Max == 0

return op.Legacy == LegacyHandshake && isInitialHandshake
}

func (op Operation) createWireMessage(
ctx context.Context,
maxTimeMS uint64,
Expand All @@ -1373,7 +1365,10 @@ func (op Operation) createWireMessage(
conn Connection,
requestID int32,
) ([]byte, startedInformation, error) {
if isLegacyHandshake(op, desc) {
isInitialHandshake := desc.WireVersion == nil || desc.WireVersion.Max == 0

// Use the OP_LEGACY on non-load-balanced connection handshakes.
if op.ServerAPI == nil && desc.Kind != description.LoadBalanced && isInitialHandshake {
return op.createLegacyHandshakeWireMessage(maxTimeMS, dst, desc)
}

Expand Down
16 changes: 0 additions & 16 deletions x/mongo/driver/operation/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,6 @@ func (h *Hello) StreamResponse(ctx context.Context, conn driver.StreamerConnecti
return h.createOperation().ExecuteExhaust(ctx, conn)
}

// isLegacyHandshake returns True if server API version is not requested and
// loadBalanced is False. If this is the case, then the drivers MUST use legacy
// hello for the first message of the initial handshake with the OP_QUERY
// protocol
func isLegacyHandshake(srvAPI *driver.ServerAPIOptions, deployment driver.Deployment) bool {
return srvAPI == nil && deployment.Kind() != description.LoadBalanced
}

func (h *Hello) createOperation() driver.Operation {
op := driver.Operation{
Clock: h.clock,
Expand All @@ -592,10 +584,6 @@ func (h *Hello) createOperation() driver.Operation {
ServerAPI: h.serverAPI,
}

if isLegacyHandshake(h.serverAPI, h.d) {
op.Legacy = driver.LegacyHandshake
}

return op
}

Expand All @@ -616,10 +604,6 @@ func (h *Hello) GetHandshakeInformation(ctx context.Context, _ address.Address,
ServerAPI: h.serverAPI,
}

if isLegacyHandshake(h.serverAPI, deployment) {
op.Legacy = driver.LegacyHandshake
}

if err := op.Execute(ctx); err != nil {
return driver.HandshakeInformation{}, err
}
Expand Down

0 comments on commit d77f8cc

Please sign in to comment.