Skip to content

Commit b0ac484

Browse files
author
Divjot Arora
authored
GODRIVER-1634 Consolidate response processing code in roundTrip (#414)
1 parent 0c7911f commit b0ac484

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)
@@ -613,12 +598,21 @@ func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) (
613598

614599
// decode
615600
res, err := op.decodeResult(wm)
616-
// Pull out $clusterTime and operationTime and update session and clock. We handle this before
617-
// handling the error to ensure we are properly gossiping the cluster time.
601+
// Update cluster/operation time and recovery tokens before handling the error to ensure we're properly updating
602+
// everything.
618603
op.updateClusterTimes(res)
619604
op.updateOperationTime(res)
605+
op.Client.UpdateRecoveryToken(bson.Raw(res))
606+
607+
if err != nil {
608+
return res, err
609+
}
620610

621-
return res, err
611+
// If there is no error, automatically attempt to decrypt all results if client side encryption is enabled.
612+
if op.Crypt != nil {
613+
return op.Crypt.Decrypt(ctx, res)
614+
}
615+
return res, nil
622616
}
623617

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

0 commit comments

Comments
 (0)