@@ -65,6 +65,9 @@ impl ClientLink {
65
65
/// Receive the next message from the Balancer that needs to be sent to this client.
66
66
pub async fn outbound_recv ( & mut self ) -> Result < SocketMessage , RecvError > {
67
67
let msg = tokio:: select! {
68
+ _ = self . room_tx. closed( ) => {
69
+ return Err ( RecvError :: Closed ) ;
70
+ }
68
71
msg = self . unicast_rx. recv( ) => {
69
72
match msg {
70
73
Some ( msg) => Ok ( msg) ,
@@ -197,8 +200,8 @@ pub async fn client_entry<'r>(
197
200
198
201
loop {
199
202
tokio:: select! {
200
- Ok ( msg) = client_link. outbound_recv( ) => {
201
- if let SocketMessage :: Message ( msg) = msg {
203
+ msg = client_link. outbound_recv( ) => {
204
+ if let Ok ( SocketMessage :: Message ( msg) ) = msg {
202
205
debug!( event = "ws" , node_id = %client_id, room = %room_name, direction = "tx" ) ;
203
206
if let Err ( err) = stream. send( msg) . await {
204
207
error!( "Error sending ws message to client: {:?}" , err) ;
@@ -239,15 +242,24 @@ pub async fn client_entry<'r>(
239
242
}
240
243
241
244
info ! ( "ending client connection" ) ;
242
- client_link
243
- . room_tx
244
- . send ( Context :: new (
245
- client_id,
246
- SocketMessage :: Message ( Message :: Close ( Some ( CloseFrame {
247
- code : CloseCode :: Normal ,
248
- reason : "client connection ended" . into ( ) ,
249
- } ) ) ) ,
250
- ) )
245
+ if !client_link. room_tx . is_closed ( ) {
246
+ client_link
247
+ . room_tx
248
+ . send ( Context :: new (
249
+ client_id,
250
+ SocketMessage :: Message ( Message :: Close ( Some ( CloseFrame {
251
+ code : CloseCode :: Normal ,
252
+ reason : "client connection ended" . into ( ) ,
253
+ } ) ) ) ,
254
+ ) )
255
+ . await ?;
256
+ }
257
+
258
+ stream
259
+ . close ( Some ( CloseFrame {
260
+ code : CloseCode :: Normal ,
261
+ reason : "client connection ended" . into ( ) ,
262
+ } ) )
251
263
. await ?;
252
264
253
265
Ok ( ( ) )
0 commit comments