@@ -3,7 +3,6 @@ use std::sync::Arc;
33use dashmap:: DashMap ;
44use dashmap:: try_result:: TryResult ;
55use futures:: channel:: mpsc:: { self , UnboundedReceiver as Receiver , UnboundedSender as Sender } ;
6- use tokio_tungstenite:: tungstenite;
76use tokio_tungstenite:: tungstenite:: error:: Error as TungsteniteError ;
87use tokio_tungstenite:: tungstenite:: protocol:: frame:: CloseFrame ;
98#[ cfg( feature = "tracing_instrument" ) ]
@@ -234,7 +233,13 @@ impl ShardRunner {
234233 }
235234 }
236235
237- // Shuts down the WebSocket client.
236+ /// Shuts down the WebSocket client.
237+ ///
238+ /// The Shard will be in an indeterminate state after this call, especially if called after
239+ /// error.
240+ ///
241+ /// Therefore, the only correct code path is to exit out of the ShardRunner loop and discard the
242+ /// WebSocket client entirely.
238243 #[ cfg_attr( feature = "tracing_instrument" , instrument( skip( self ) ) ) ]
239244 async fn shutdown ( & mut self , close_code : u16 ) {
240245 debug ! ( "[ShardRunner {:?}] Shutting down." , self . shard. shard_info( ) ) ;
@@ -248,22 +253,6 @@ impl ShardRunner {
248253 } ) )
249254 . await ,
250255 ) ;
251-
252- // In return, we wait for either a Close Frame response, or an error, after which this WS
253- // is deemed disconnected from Discord.
254- loop {
255- match self . shard . client . next ( ) . await {
256- Some ( Ok ( tungstenite:: Message :: Close ( _) ) ) => return ,
257- Some ( Err ( _) ) => {
258- warn ! (
259- "[ShardRunner {:?}] Received an error awaiting close frame" ,
260- self . shard. shard_info( ) ,
261- ) ;
262- return ;
263- } ,
264- _ => { } ,
265- }
266- }
267256 }
268257
269258 #[ cfg( feature = "voice" ) ]
0 commit comments