@@ -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 )
@@ -613,12 +598,21 @@ func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) (
613
598
614
599
// decode
615
600
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 .
618
603
op .updateClusterTimes (res )
619
604
op .updateOperationTime (res )
605
+ op .Client .UpdateRecoveryToken (bson .Raw (res ))
606
+
607
+ if err != nil {
608
+ return res , err
609
+ }
620
610
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
622
616
}
623
617
624
618
// moreToComeRoundTrip writes a wiremessage to the provided connection. This is used when an OP_MSG is
0 commit comments