@@ -117,14 +117,9 @@ void _checkClosed(){
117
117
}
118
118
119
119
WriteResult _checkWriteError ( DB db , MyPort mp , DBPort port , WriteConcern concern )
120
- throws MongoException {
120
+ throws MongoException , IOException {
121
121
CommandResult e = null ;
122
- try {
123
- e = port .runCommand ( db , concern .getCommand () );
124
- } catch ( IOException ioe ){
125
- throw new MongoException .Network ( ioe .getMessage () , ioe );
126
- }
127
- mp .done ( port );
122
+ e = port .runCommand ( db , concern .getCommand () );
128
123
129
124
Object foo = e .get ( "err" );
130
125
if ( foo == null )
@@ -162,7 +157,6 @@ public WriteResult say( DB db , OutMessage m , WriteConcern concern , ServerAddr
162
157
return _checkWriteError ( db , mp , port , concern );
163
158
}
164
159
else {
165
- mp .done ( port );
166
160
return new WriteResult ( db , port , concern );
167
161
}
168
162
}
@@ -186,6 +180,7 @@ public WriteResult say( DB db , OutMessage m , WriteConcern concern , ServerAddr
186
180
throw re ;
187
181
}
188
182
finally {
183
+ mp .done ( port );
189
184
m .doneWithMessage ();
190
185
}
191
186
}
@@ -210,26 +205,30 @@ public Response call( DB db , DBCollection coll , OutMessage m , ServerAddress h
210
205
final DBPort port = mp .get ( false , slaveOk , hostNeeded );
211
206
212
207
Response res = null ;
208
+ boolean retry = false ;
213
209
try {
214
210
port .checkAuth ( db );
215
211
res = port .call ( m , coll );
216
- mp .done ( port );
217
212
if ( res ._responseTo != m .getId () )
218
213
throw new MongoException ( "ids don't match" );
219
214
}
220
215
catch ( IOException ioe ){
221
- boolean shouldRetry = _error ( ioe , slaveOk ) && ! coll ._name .equals ( "$cmd" ) && retries > 0 ;
222
216
mp .error ( port , ioe );
223
- if ( shouldRetry ){
224
- return call ( db , coll , m , hostNeeded , retries - 1 );
217
+ retry = _error ( ioe , slaveOk ) && ! coll ._name .equals ( "$cmd" ) && retries > 0 ;
218
+ if ( !retry ){
219
+ throw new MongoException .Network ( "can't call something" , ioe );
225
220
}
226
- throw new MongoException .Network ( "can't call something" , ioe );
227
221
}
228
222
catch ( RuntimeException re ){
229
223
mp .error ( port , re );
230
224
throw re ;
225
+ } finally {
226
+ mp .done ( port );
231
227
}
232
-
228
+
229
+ if (retry )
230
+ return call ( db , coll , m , hostNeeded , retries - 1 );
231
+
233
232
ServerError err = res .getError ();
234
233
235
234
if ( err != null && err .isNotMasterError () ){
@@ -356,8 +355,6 @@ void done( DBPort p ){
356
355
*/
357
356
void error ( DBPort p , Exception e ){
358
357
p .close ();
359
- p .getPool ().done ( p );
360
-
361
358
_requestPort = null ;
362
359
_logger .log ( Level .SEVERE , "MyPort.error called" , e );
363
360
}
0 commit comments