@@ -227,14 +227,11 @@ synchronized void doCommandAsync(Command c) {
227
227
}
228
228
229
229
void submitUserTask (final String name , final Runnable task ) {
230
- userThreadPool .submit (new Runnable () {
231
- @ Override
232
- public void run () {
233
- try {
234
- task .run ();
235
- } catch (Throwable throwable ) {
236
- log .error (name + " threw an exception" , throwable );
237
- }
230
+ userThreadPool .submit (() -> {
231
+ try {
232
+ task .run ();
233
+ } catch (Throwable throwable ) {
234
+ log .error (name + " threw an exception" , throwable );
238
235
}
239
236
});
240
237
}
@@ -250,21 +247,18 @@ FileTransferHelper getFileTransferHelper() {
250
247
void fireDisconnect () {
251
248
connected .set (false );
252
249
253
- submitUserTask ("ConnectionHandler disconnect task" , new Runnable () {
254
- @ Override
255
- public void run () {
256
- handleDisconnect ();
257
- }
258
- });
250
+ submitUserTask ("ConnectionHandler disconnect task" , this ::handleDisconnect );
259
251
}
260
252
261
- private synchronized void handleDisconnect () {
253
+ private void handleDisconnect () {
262
254
try {
263
255
connectionHandler .onDisconnect (this );
264
256
} finally {
265
- if (!connected .get ()) {
266
- shuttingDown .set (true ); // Try to prevent extraneous exit commands
267
- shutDown ();
257
+ synchronized (this ) {
258
+ if (!connected .get ()) {
259
+ shuttingDown .set (true ); // Try to prevent extraneous exit commands
260
+ shutDown ();
261
+ }
268
262
}
269
263
}
270
264
}
@@ -281,12 +275,21 @@ private ReconnectQuery(TS3Query query, QueryIO io) {
281
275
282
276
@ Override
283
277
public void connect () {
284
- throw new UnsupportedOperationException ("Can't call connect from onConnect" );
278
+ throw new UnsupportedOperationException ("Can't call connect from onConnect handler " );
285
279
}
286
280
287
281
@ Override
288
282
public void exit () {
289
283
parent .exit ();
290
284
}
285
+
286
+ @ Override
287
+ synchronized void fireDisconnect () {
288
+ // If a reconnect query fails, we do not want this to affect the parent query.
289
+ // Instead, simply fail all remaining onConnect commands.
290
+ QueryIO io = super .io ;
291
+ io .disconnect ();
292
+ io .failRemainingCommands ();
293
+ }
291
294
}
292
295
}
0 commit comments