From 66f247d005cb825d6819c5270eb4866ba2668948 Mon Sep 17 00:00:00 2001 From: Divjot Arora Date: Fri, 29 May 2020 13:48:45 -0400 Subject: [PATCH] GODRIVER-1634 Consolidate response processing code in roundTrip (#414) --- x/mongo/driver/operation.go | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/x/mongo/driver/operation.go b/x/mongo/driver/operation.go index 493e9b01a0..3e388b6704 100644 --- a/x/mongo/driver/operation.go +++ b/x/mongo/driver/operation.go @@ -374,21 +374,6 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error { finishedInfo.cmdErr = err op.publishFinishedEvent(ctx, finishedInfo) - // Pull out $clusterTime and operationTime and update session and clock. We handle this before - // handling the error to ensure we are properly gossiping the cluster time. - op.updateClusterTimes(res) - op.updateOperationTime(res) - op.Client.UpdateRecoveryToken(bson.Raw(res)) - - // automatically attempt to decrypt all results if client side encryption enabled - if op.Crypt != nil { - // use decryptErr isntead of err because err is used below for retrying - var decryptErr error - res, decryptErr = op.Crypt.Decrypt(ctx, res) - if decryptErr != nil { - return decryptErr - } - } var perr error if op.ProcessResponseFn != nil { perr = op.ProcessResponseFn(res, srvr, desc.Server) @@ -583,12 +568,21 @@ func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) ( // decode res, err := op.decodeResult(wm) - // Pull out $clusterTime and operationTime and update session and clock. We handle this before - // handling the error to ensure we are properly gossiping the cluster time. + // Update cluster/operation time and recovery tokens before handling the error to ensure we're properly updating + // everything. op.updateClusterTimes(res) op.updateOperationTime(res) + op.Client.UpdateRecoveryToken(bson.Raw(res)) + + if err != nil { + return res, err + } - return res, err + // If there is no error, automatically attempt to decrypt all results if client side encryption is enabled. + if op.Crypt != nil { + return op.Crypt.Decrypt(ctx, res) + } + return res, nil } // moreToComeRoundTrip writes a wiremessage to the provided connection. This is used when an OP_MSG is