@@ -352,9 +352,17 @@ public void initChannel(SocketChannel ch) {
352
352
this .executorServiceClosing =
353
353
Utils .makeIdempotent (
354
354
() -> {
355
- this .dispatchingExecutorService .shutdownNow ();
356
355
if (dispatchingExecutorServiceFactory == null ) {
357
- this .dispatchingExecutorService .shutdownNow ();
356
+ List <Runnable > outstandingTasks = this .dispatchingExecutorService .shutdownNow ();
357
+ for (Runnable outstandingTask : outstandingTasks ) {
358
+ try {
359
+ outstandingTask .run ();
360
+ } catch (Exception e ) {
361
+ LOGGER .info (
362
+ "Error while releasing buffer in outstanding connection tasks: {}" ,
363
+ e .getMessage ());
364
+ }
365
+ }
358
366
} else {
359
367
dispatchingExecutorServiceFactory .clientClosed (this .dispatchingExecutorService );
360
368
}
@@ -2770,7 +2778,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
2770
2778
}
2771
2779
} else {
2772
2780
FrameHandler frameHandler = ServerFrameHandler .lookup (commandId , version , m );
2773
- task = () -> frameHandler .handle (Client .this , frameSize , ctx , m );
2781
+ // task = () -> frameHandler.handle(Client.this, frameSize, ctx, m);
2782
+ task = new FrameHandlerTask (frameHandler , Client .this , frameSize , ctx , m , closing );
2774
2783
}
2775
2784
2776
2785
if (task != null ) {
@@ -2839,6 +2848,44 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
2839
2848
}
2840
2849
}
2841
2850
2851
+ private static class FrameHandlerTask implements Runnable {
2852
+
2853
+ private final FrameHandler frameHandler ;
2854
+ private final Client client ;
2855
+ private final int frameSize ;
2856
+ private final ChannelHandlerContext ctx ;
2857
+ private final ByteBuf message ;
2858
+ private final AtomicBoolean closing ;
2859
+
2860
+ private FrameHandlerTask (
2861
+ FrameHandler frameHandler ,
2862
+ Client client ,
2863
+ int frameSize ,
2864
+ ChannelHandlerContext ctx ,
2865
+ ByteBuf message ,
2866
+ AtomicBoolean closing ) {
2867
+ this .frameHandler = frameHandler ;
2868
+ this .client = client ;
2869
+ this .frameSize = frameSize ;
2870
+ this .ctx = ctx ;
2871
+ this .message = message ;
2872
+ this .closing = closing ;
2873
+ }
2874
+
2875
+ @ Override
2876
+ public void run () {
2877
+ if (this .closing .get ()) {
2878
+ try {
2879
+ this .message .release ();
2880
+ } catch (Exception e ) {
2881
+ e .printStackTrace ();
2882
+ }
2883
+ } else {
2884
+ this .frameHandler .handle (this .client , this .frameSize , this .ctx , this .message );
2885
+ }
2886
+ }
2887
+ }
2888
+
2842
2889
private <T > OutstandingRequest <T > outstandingRequest () {
2843
2890
return new OutstandingRequest <>(this .rpcTimeout , this .host + ":" + this .port );
2844
2891
}
0 commit comments