@@ -88,13 +88,10 @@ public void onResult(final AsyncReadWriteBinding binding, final Throwable t) {
8888 operation .executeAsync (binding , new SingleResultCallback <T >() {
8989 @ Override
9090 public void onResult (final T result , final Throwable t ) {
91- try {
92- labelException (t , session );
93- unpinServerAddressOnTransientTransactionError (session , t );
94- errHandlingCallback .onResult (result , t );
95- } finally {
96- binding .release ();
97- }
91+ labelException (session , t );
92+ unpinServerAddressOnTransientTransactionError (session , t );
93+ binding .release ();
94+ errHandlingCallback .onResult (result , t );
9895 }
9996 });
10097 }
@@ -134,13 +131,10 @@ public void onResult(final AsyncReadWriteBinding binding, final Throwable t) {
134131 operation .executeAsync (binding , new SingleResultCallback <T >() {
135132 @ Override
136133 public void onResult (final T result , final Throwable t ) {
137- try {
138- labelException (t , session );
139- unpinServerAddressOnTransientTransactionError (session , t );
140- errHandlingCallback .onResult (result , t );
141- } finally {
142- binding .release ();
143- }
134+ labelException (session , t );
135+ unpinServerAddressOnTransientTransactionError (session , t );
136+ binding .release ();
137+ errHandlingCallback .onResult (result , t );
144138 }
145139 });
146140 }
@@ -151,7 +145,7 @@ public void onResult(final T result, final Throwable t) {
151145 });
152146 }
153147
154- private void labelException (final Throwable t , final ClientSession session ) {
148+ private void labelException (@ Nullable final ClientSession session , @ Nullable final Throwable t ) {
155149 if (session != null && session .hasActiveTransaction ()
156150 && (t instanceof MongoSocketException || t instanceof MongoTimeoutException
157151 || (t instanceof MongoQueryException && ((MongoQueryException ) t ).getErrorCode () == 91 ))
@@ -160,8 +154,9 @@ private void labelException(final Throwable t, final ClientSession session) {
160154 }
161155 }
162156
163- private void unpinServerAddressOnTransientTransactionError (final @ Nullable ClientSession session , final Throwable throwable ) {
164- if (session != null && throwable != null && throwable instanceof MongoException
157+ private void unpinServerAddressOnTransientTransactionError (@ Nullable final ClientSession session ,
158+ @ Nullable final Throwable throwable ) {
159+ if (session != null && throwable instanceof MongoException
165160 && ((MongoException ) throwable ).hasErrorLabel (TRANSIENT_TRANSACTION_ERROR_LABEL )) {
166161 session .setPinnedServerAddress (null );
167162 }
0 commit comments