@@ -86,13 +86,10 @@ public void onResult(final AsyncReadWriteBinding binding, final Throwable t) {
86
86
operation .executeAsync (binding , new SingleResultCallback <T >() {
87
87
@ Override
88
88
public void onResult (final T result , final Throwable t ) {
89
- try {
90
- labelException (t , session );
91
- unpinServerAddressOnTransientTransactionError (session , t );
92
- errHandlingCallback .onResult (result , t );
93
- } finally {
94
- binding .release ();
95
- }
89
+ labelException (session , t );
90
+ unpinServerAddressOnTransientTransactionError (session , t );
91
+ binding .release ();
92
+ errHandlingCallback .onResult (result , t );
96
93
}
97
94
});
98
95
}
@@ -132,13 +129,10 @@ public void onResult(final AsyncReadWriteBinding binding, final Throwable t) {
132
129
operation .executeAsync (binding , new SingleResultCallback <T >() {
133
130
@ Override
134
131
public void onResult (final T result , final Throwable t ) {
135
- try {
136
- labelException (t , session );
137
- unpinServerAddressOnTransientTransactionError (session , t );
138
- errHandlingCallback .onResult (result , t );
139
- } finally {
140
- binding .release ();
141
- }
132
+ labelException (session , t );
133
+ unpinServerAddressOnTransientTransactionError (session , t );
134
+ binding .release ();
135
+ errHandlingCallback .onResult (result , t );
142
136
}
143
137
});
144
138
}
@@ -149,7 +143,7 @@ public void onResult(final T result, final Throwable t) {
149
143
});
150
144
}
151
145
152
- private void labelException (final Throwable t , final AsyncClientSession session ) {
146
+ private void labelException (@ Nullable final AsyncClientSession session , @ Nullable final Throwable t ) {
153
147
if (session != null && session .hasActiveTransaction ()
154
148
&& (t instanceof MongoSocketException || t instanceof MongoTimeoutException
155
149
|| (t instanceof MongoQueryException && ((MongoQueryException ) t ).getErrorCode () == 91 ))
@@ -158,8 +152,9 @@ private void labelException(final Throwable t, final AsyncClientSession session)
158
152
}
159
153
}
160
154
161
- private void unpinServerAddressOnTransientTransactionError (final @ Nullable AsyncClientSession session , final Throwable throwable ) {
162
- if (session != null && throwable != null && throwable instanceof MongoException
155
+ private void unpinServerAddressOnTransientTransactionError (@ Nullable final AsyncClientSession session ,
156
+ @ Nullable final Throwable throwable ) {
157
+ if (session != null && throwable instanceof MongoException
163
158
&& ((MongoException ) throwable ).hasErrorLabel (TRANSIENT_TRANSACTION_ERROR_LABEL )) {
164
159
session .setPinnedServerAddress (null );
165
160
}
0 commit comments