@@ -380,39 +380,45 @@ protected boolean shutdown(Throwable cause) throws JMSException {
380
380
// Ensure that no asynchronous completion sends remain blocked after close but wait
381
381
// using the close timeout for the asynchronous sends to complete normally.
382
382
final ExecutorService completionExecutor = getCompletionExecutor ();
383
+ try {
384
+ synchronized (sessionInfo ) {
385
+ // Producers are now quiesced and we can await completion of asynchronous sends
386
+ // that are still pending a result or timeout once we've done a quick check to
387
+ // see if any are actually pending or have completed already.
388
+ asyncSendsCompletion = connection .newProviderFuture ();
389
+
390
+ if (asyncSendsCompletion != null ) {
391
+ completionExecutor .execute (() -> {
392
+ if (asyncSendQueue .isEmpty ()) {
393
+ asyncSendsCompletion .onSuccess ();
394
+ }
395
+ });
396
+ }
397
+ }
383
398
384
- synchronized ( sessionInfo ) {
385
- // Producers are now quiesced and we can await completion of asynchronous sends
386
- // that are still pending a result or timeout once we've done a quick check to
387
- // see if any are actually pending or have completed already.
388
- asyncSendsCompletion = connection . newProviderFuture ();
389
-
390
- completionExecutor . execute (() -> {
391
- if (asyncSendQueue . isEmpty () ) {
392
- asyncSendsCompletion . onSuccess ( );
399
+ try {
400
+ if ( asyncSendsCompletion != null ) {
401
+ asyncSendsCompletion . sync ( connection . getCloseTimeout (), TimeUnit . MILLISECONDS );
402
+ }
403
+ } catch ( Exception ex ) {
404
+ LOG . trace ( "Exception during wait for asynchronous sends to complete" , ex );
405
+ } finally {
406
+ if (cause == null ) {
407
+ cause = new JMSException ( "Session closed remotely before message transfer result was notified" );
393
408
}
394
- });
395
- }
396
409
397
- try {
398
- asyncSendsCompletion .sync (connection .getCloseTimeout (), TimeUnit .MILLISECONDS );
399
- } catch (Exception ex ) {
400
- LOG .trace ("Exception during wait for asynchronous sends to complete" , ex );
401
- } finally {
402
- if (cause == null ) {
403
- cause = new JMSException ("Session closed remotely before message transfer result was notified" );
410
+ // as a last task we want to fail any stragglers in the asynchronous send queue and then
411
+ // shutdown the queue to prevent any more submissions while the cleanup goes on.
412
+ completionExecutor .execute (new FailOrCompleteAsyncCompletionsTask (JmsExceptionSupport .create (cause )));
404
413
}
405
-
406
- // as a last task we want to fail any stragglers in the asynchronous send queue and then
407
- // shutdown the queue to prevent any more submissions while the cleanup goes on.
408
- completionExecutor .execute (new FailOrCompleteAsyncCompletionsTask (JmsExceptionSupport .create (cause )));
414
+ } finally {
409
415
completionExecutor .shutdown ();
410
- }
411
416
412
- try {
413
- completionExecutor .awaitTermination (connection .getCloseTimeout (), TimeUnit .MILLISECONDS );
414
- } catch (InterruptedException e ) {
415
- LOG .trace ("Session close awaiting send completions was interrupted" );
417
+ try {
418
+ completionExecutor .awaitTermination (connection .getCloseTimeout (), TimeUnit .MILLISECONDS );
419
+ } catch (InterruptedException e ) {
420
+ LOG .trace ("Session close awaiting send completions was interrupted" );
421
+ }
416
422
}
417
423
418
424
if (shutdownError != null ) {
0 commit comments