Skip to content

Commit 999fc10

Browse files
committed
JAVA-614: Move fall to OutMessage#doneWithMessage to finally block in DBTCPConnector#call
1 parent 72ad520 commit 999fc10

File tree

1 file changed

+45
-42
lines changed

1 file changed

+45
-42
lines changed

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -248,59 +248,62 @@ public Response call( DB db , DBCollection coll , OutMessage m , ServerAddress h
248248
@Override
249249
public Response call( DB db, DBCollection coll, OutMessage m, ServerAddress hostNeeded, int retries, ReadPreference readPref, DBDecoder decoder ){
250250

251-
if (readPref == null)
252-
readPref = ReadPreference.PRIMARY;
251+
try {
252+
if (readPref == null)
253+
readPref = ReadPreference.PRIMARY;
253254

254-
if (readPref == ReadPreference.PRIMARY && m.hasOption( Bytes.QUERYOPTION_SLAVEOK ))
255-
readPref = ReadPreference.secondaryPreferred();
255+
if (readPref == ReadPreference.PRIMARY && m.hasOption( Bytes.QUERYOPTION_SLAVEOK ))
256+
readPref = ReadPreference.secondaryPreferred();
256257

257-
boolean secondaryOk = !(readPref == ReadPreference.PRIMARY);
258+
boolean secondaryOk = !(readPref == ReadPreference.PRIMARY);
258259

259-
_checkClosed();
260-
checkMaster( false, !secondaryOk );
260+
_checkClosed();
261+
checkMaster( false, !secondaryOk );
261262

262-
final MyPort mp = _myPort.get();
263-
final DBPort port = mp.get( false , readPref, hostNeeded );
263+
final MyPort mp = _myPort.get();
264+
final DBPort port = mp.get( false , readPref, hostNeeded );
264265

265-
Response res = null;
266-
boolean retry = false;
267-
try {
268-
port.checkAuth( db );
269-
res = port.call( m , coll, readPref, decoder );
270-
if ( res._responseTo != m.getId() )
271-
throw new MongoException( "ids don't match" );
272-
}
273-
catch ( IOException ioe ){
274-
mp.error( port , ioe );
275-
retry = retries > 0 && !coll._name.equals( "$cmd" )
276-
&& !(ioe instanceof SocketTimeoutException) && _error( ioe, secondaryOk );
277-
if ( !retry ){
278-
throw new MongoException.Network( "can't call something : " + port.host() + "/" + db,
279-
ioe );
266+
Response res = null;
267+
boolean retry = false;
268+
try {
269+
port.checkAuth( db );
270+
res = port.call( m , coll, readPref, decoder );
271+
if ( res._responseTo != m.getId() )
272+
throw new MongoException( "ids don't match" );
273+
}
274+
catch ( IOException ioe ){
275+
mp.error( port , ioe );
276+
retry = retries > 0 && !coll._name.equals( "$cmd" )
277+
&& !(ioe instanceof SocketTimeoutException) && _error( ioe, secondaryOk );
278+
if ( !retry ){
279+
throw new MongoException.Network( "can't call something : " + port.host() + "/" + db,
280+
ioe );
281+
}
282+
}
283+
catch ( RuntimeException re ){
284+
mp.error( port , re );
285+
throw re;
286+
} finally {
287+
mp.done( port );
280288
}
281-
}
282-
catch ( RuntimeException re ){
283-
mp.error( port , re );
284-
throw re;
285-
} finally {
286-
mp.done( port );
287-
}
288289

289-
if (retry)
290-
return call( db , coll , m , hostNeeded , retries - 1 , readPref, decoder );
290+
if (retry)
291+
return call( db , coll , m , hostNeeded , retries - 1 , readPref, decoder );
291292

292-
ServerError err = res.getError();
293+
ServerError err = res.getError();
293294

294-
if ( err != null && err.isNotMasterError() ){
295-
checkMaster( true , true );
296-
if ( retries <= 0 ){
297-
throw new MongoException( "not talking to master and retries used up" );
295+
if ( err != null && err.isNotMasterError() ){
296+
checkMaster( true , true );
297+
if ( retries <= 0 ){
298+
throw new MongoException( "not talking to master and retries used up" );
299+
}
300+
return call( db , coll , m , hostNeeded , retries -1, readPref, decoder );
298301
}
299-
return call( db , coll , m , hostNeeded , retries -1, readPref, decoder );
300-
}
301302

302-
m.doneWithMessage();
303-
return res;
303+
return res;
304+
} finally {
305+
m.doneWithMessage();
306+
}
304307
}
305308

306309
public ServerAddress getAddress(){

0 commit comments

Comments
 (0)