@@ -248,46 +248,50 @@ public Mono<Void> closeGracefully() {
248
248
return Mono .fromRunnable (() -> {
249
249
isClosing = true ;
250
250
logger .debug ("Initiating graceful shutdown" );
251
- }).then (Mono .defer (() -> {
252
- // First complete the sinks to stop processing
253
- inboundSink .tryEmitComplete ();
254
- outboundSink .tryEmitComplete ();
255
- return Mono .delay (Duration .ofMillis (200 ));
256
- })).then (Mono .fromRunnable (() -> {
257
- try {
258
- // Dispose schedulers first
259
- inboundScheduler .dispose ();
260
- outboundScheduler .dispose ();
261
-
262
- // Wait for schedulers to terminate
263
- if (!inboundScheduler .isDisposed ()) {
264
- inboundScheduler .disposeGracefully ().block (Duration .ofSeconds (5 ));
265
- }
266
- if (!outboundScheduler .isDisposed ()) {
267
- outboundScheduler .disposeGracefully ().block (Duration .ofSeconds (5 ));
268
- }
269
-
270
- // Only after schedulers are disposed, close the streams
251
+ })
252
+ // .then(Mono.defer(() -> {
253
+ // // First complete the sinks to stop processing
254
+ // inboundSink.tryEmitComplete();
255
+ // outboundSink.tryEmitComplete();
256
+ // return Mono.delay(Duration.ofMillis(100));
257
+ // }))
258
+ .then (Mono .fromRunnable (() -> {
271
259
try {
272
- if (inputStream != System .in ) {
273
- inputStream .close ();
260
+ // Dispose schedulers first
261
+ inboundScheduler .dispose ();
262
+ outboundScheduler .dispose ();
263
+
264
+ // Wait for schedulers to terminate
265
+ if (!inboundScheduler .isDisposed ()) {
266
+ inboundScheduler .disposeGracefully ().block (Duration .ofSeconds (5 ));
267
+ }
268
+ if (!outboundScheduler .isDisposed ()) {
269
+ outboundScheduler .disposeGracefully ().block (Duration .ofSeconds (5 ));
270
+ }
271
+
272
+ // Only after schedulers are disposed, close the streams
273
+ try {
274
+ if (inputStream != System .in ) {
275
+ inputStream .close ();
276
+ }
277
+ if (outputStream != System .out ) {
278
+ outputStream .flush ();
279
+ outputStream .close ();
280
+ }
274
281
}
275
- if ( outputStream != System . out ) {
276
- outputStream . flush ();
277
- outputStream . close ( );
282
+ catch ( IOException e ) {
283
+ // Log but don't throw since we're shutting down
284
+ logger . debug ( "Error closing streams during shutdown" , e );
278
285
}
286
+
287
+ logger .info ("Graceful shutdown completed" );
279
288
}
280
- catch (IOException e ) {
281
- // Log but don't throw since we're shutting down
282
- logger .debug ("Error closing streams during shutdown" , e );
289
+ catch (Exception e ) {
290
+ logger .error ("Error during graceful shutdown" , e );
283
291
}
284
-
285
- logger .info ("Graceful shutdown completed" );
286
- }
287
- catch (Exception e ) {
288
- logger .error ("Error during graceful shutdown" , e );
289
- }
290
- })).then ().subscribeOn (Schedulers .boundedElastic ());
292
+ }))
293
+ .then ()
294
+ .subscribeOn (Schedulers .boundedElastic ());
291
295
}
292
296
293
297
@ Override
0 commit comments