This repository was archived by the owner on Jun 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
src/main/java/com/mewna/catnip/shard/manager Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 158
158
<groupId >ch.qos.logback</groupId >
159
159
<artifactId >logback-classic</artifactId >
160
160
<version >${logback.version} </version >
161
- <!-- <scope>test</scope> -- >
161
+ <scope >test</scope >
162
162
</dependency >
163
163
164
164
<!-- Deep/recursive field by field comparing ignoring any equals() methods -->
Original file line number Diff line number Diff line change 32
32
import com .mewna .catnip .shard .CatnipShard ;
33
33
import com .mewna .catnip .shard .CatnipShardImpl ;
34
34
import com .mewna .catnip .shard .LifecycleEvent .Raw ;
35
+ import com .mewna .catnip .shard .LifecycleState ;
35
36
import com .mewna .catnip .shard .event .MessageConsumer ;
36
37
import com .mewna .catnip .util .task .QueueTask ;
37
38
import com .mewna .catnip .util .task .ShardConnectTask ;
@@ -283,6 +284,28 @@ public void shutdown() {
283
284
consumers .forEach (MessageConsumer ::close );
284
285
consumers .clear ();
285
286
shards .values ().forEach (CatnipShard ::disconnect );
287
+ // Spin waiting for shards to disconnect
288
+ final var blockingStates = Set .of (
289
+ LifecycleState .CONNECTING ,
290
+ LifecycleState .CONNECTED ,
291
+ LifecycleState .IDENTIFYING ,
292
+ LifecycleState .RESUMING ,
293
+ LifecycleState .LOGGED_IN
294
+ );
295
+ var cycles = 0 ;
296
+ while (shards .values ().stream ().anyMatch (shard -> shard .isConnected () || blockingStates .contains (shard .lifecycleState ()))) {
297
+ catnip ().logAdapter ().debug ("Waiting for shards to disconnect..." );
298
+ try {
299
+ //noinspection BusyWait
300
+ Thread .sleep (50L );
301
+ ++cycles ;
302
+ if (cycles >= 100 ) {
303
+ catnip ().logAdapter ().error ("Shards took too long to disconnect (probably ~5s), giving up!" );
304
+ break ;
305
+ }
306
+ } catch (final InterruptedException ignored ) {
307
+ }
308
+ }
286
309
shards .clear ();
287
310
}
288
311
}
You can’t perform that action at this time.
0 commit comments