@@ -88,13 +88,10 @@ public void onResult(final AsyncReadWriteBinding binding, final Throwable t) {
88
88
operation .executeAsync (binding , new SingleResultCallback <T >() {
89
89
@ Override
90
90
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 );
98
95
}
99
96
});
100
97
}
@@ -134,13 +131,10 @@ public void onResult(final AsyncReadWriteBinding binding, final Throwable t) {
134
131
operation .executeAsync (binding , new SingleResultCallback <T >() {
135
132
@ Override
136
133
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 );
144
138
}
145
139
});
146
140
}
@@ -151,7 +145,7 @@ public void onResult(final T result, final Throwable t) {
151
145
});
152
146
}
153
147
154
- private void labelException (final Throwable t , final ClientSession session ) {
148
+ private void labelException (@ Nullable final ClientSession session , @ Nullable final Throwable t ) {
155
149
if (session != null && session .hasActiveTransaction ()
156
150
&& (t instanceof MongoSocketException || t instanceof MongoTimeoutException
157
151
|| (t instanceof MongoQueryException && ((MongoQueryException ) t ).getErrorCode () == 91 ))
@@ -160,8 +154,9 @@ private void labelException(final Throwable t, final ClientSession session) {
160
154
}
161
155
}
162
156
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
165
160
&& ((MongoException ) throwable ).hasErrorLabel (TRANSIENT_TRANSACTION_ERROR_LABEL )) {
166
161
session .setPinnedServerAddress (null );
167
162
}
0 commit comments