Skip to content

Commit 66f247d

Browse files
author
Divjot Arora
committed
GODRIVER-1634 Consolidate response processing code in roundTrip (#414)
1 parent eced6de commit 66f247d

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

x/mongo/driver/operation.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -374,21 +374,6 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
374374
finishedInfo.cmdErr = err
375375
op.publishFinishedEvent(ctx, finishedInfo)
376376

377-
// Pull out $clusterTime and operationTime and update session and clock. We handle this before
378-
// handling the error to ensure we are properly gossiping the cluster time.
379-
op.updateClusterTimes(res)
380-
op.updateOperationTime(res)
381-
op.Client.UpdateRecoveryToken(bson.Raw(res))
382-
383-
// automatically attempt to decrypt all results if client side encryption enabled
384-
if op.Crypt != nil {
385-
// use decryptErr isntead of err because err is used below for retrying
386-
var decryptErr error
387-
res, decryptErr = op.Crypt.Decrypt(ctx, res)
388-
if decryptErr != nil {
389-
return decryptErr
390-
}
391-
}
392377
var perr error
393378
if op.ProcessResponseFn != nil {
394379
perr = op.ProcessResponseFn(res, srvr, desc.Server)
@@ -583,12 +568,21 @@ func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) (
583568

584569
// decode
585570
res, err := op.decodeResult(wm)
586-
// Pull out $clusterTime and operationTime and update session and clock. We handle this before
587-
// handling the error to ensure we are properly gossiping the cluster time.
571+
// Update cluster/operation time and recovery tokens before handling the error to ensure we're properly updating
572+
// everything.
588573
op.updateClusterTimes(res)
589574
op.updateOperationTime(res)
575+
op.Client.UpdateRecoveryToken(bson.Raw(res))
576+
577+
if err != nil {
578+
return res, err
579+
}
590580

591-
return res, err
581+
// If there is no error, automatically attempt to decrypt all results if client side encryption is enabled.
582+
if op.Crypt != nil {
583+
return op.Crypt.Decrypt(ctx, res)
584+
}
585+
return res, nil
592586
}
593587

594588
// moreToComeRoundTrip writes a wiremessage to the provided connection. This is used when an OP_MSG is

0 commit comments

Comments
 (0)