1414
1515"""CommandCursor class to iterate over command results."""
1616
17+ import datetime
18+
1719from collections import deque
1820
1921from bson .py3compat import integer_types
2022from pymongo import helpers , monitoring
21- from pymongo .errors import AutoReconnect , CursorNotFound , NotMasterError
23+ from pymongo .errors import AutoReconnect , NotMasterError , OperationFailure
2224from pymongo .message import _GetMore
2325
2426
@@ -101,16 +103,19 @@ def __send_message(self, operation):
101103 raise
102104
103105 publish = monitoring .enabled ()
104- duration = response .duration
106+ cmd_duration = response .duration
105107 rqst_id = response .request_id
108+ if publish :
109+ start = datetime .datetime .now ()
106110 try :
107111 doc = helpers ._unpack_response (response .data ,
108112 self .__id ,
109113 self .__collection .codec_options )
110- except CursorNotFound as exc :
114+ except OperationFailure as exc :
111115 self .__killed = True
112116
113117 if publish :
118+ duration = (datetime .datetime .now () - start ) + cmd_duration
114119 monitoring .publish_command_failure (
115120 duration , exc .details , "getMore" , rqst_id , self .__address )
116121
@@ -121,13 +126,15 @@ def __send_message(self, operation):
121126 self .__killed = True
122127
123128 if publish :
129+ duration = (datetime .datetime .now () - start ) + cmd_duration
124130 monitoring .publish_command_failure (
125131 duration , exc .details , "getMore" , rqst_id , self .__address )
126132
127133 client ._reset_server_and_request_check (self .address )
128134 raise
129135
130136 if publish :
137+ duration = (datetime .datetime .now () - start ) + cmd_duration
131138 # Must publish in getMore command response format.
132139 res = {"cursor" : {"id" : doc ["cursor_id" ],
133140 "ns" : self .__collection .full_name ,
0 commit comments