@@ -374,21 +374,6 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
374
374
finishedInfo .cmdErr = err
375
375
op .publishFinishedEvent (ctx , finishedInfo )
376
376
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
- }
392
377
var perr error
393
378
if op .ProcessResponseFn != nil {
394
379
perr = op .ProcessResponseFn (res , srvr , desc .Server )
@@ -583,12 +568,21 @@ func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) (
583
568
584
569
// decode
585
570
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 .
588
573
op .updateClusterTimes (res )
589
574
op .updateOperationTime (res )
575
+ op .Client .UpdateRecoveryToken (bson .Raw (res ))
576
+
577
+ if err != nil {
578
+ return res , err
579
+ }
590
580
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
592
586
}
593
587
594
588
// moreToComeRoundTrip writes a wiremessage to the provided connection. This is used when an OP_MSG is
0 commit comments