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 158158 <groupId >ch.qos.logback</groupId >
159159 <artifactId >logback-classic</artifactId >
160160 <version >${logback.version} </version >
161- <!-- <scope>test</scope> -- >
161+ <scope >test</scope >
162162 </dependency >
163163
164164 <!-- Deep/recursive field by field comparing ignoring any equals() methods -->
Original file line number Diff line number Diff line change 3232import com .mewna .catnip .shard .CatnipShard ;
3333import com .mewna .catnip .shard .CatnipShardImpl ;
3434import com .mewna .catnip .shard .LifecycleEvent .Raw ;
35+ import com .mewna .catnip .shard .LifecycleState ;
3536import com .mewna .catnip .shard .event .MessageConsumer ;
3637import com .mewna .catnip .util .task .QueueTask ;
3738import com .mewna .catnip .util .task .ShardConnectTask ;
@@ -283,6 +284,28 @@ public void shutdown() {
283284 consumers .forEach (MessageConsumer ::close );
284285 consumers .clear ();
285286 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+ }
286309 shards .clear ();
287310 }
288311}
You can’t perform that action at this time.
0 commit comments