Fix memory leak (#3066)
This commit is contained in:
parent
3b5a7411cf
commit
08ec62cbe1
1 changed files with 58 additions and 48 deletions
|
@ -180,8 +180,7 @@ impl Connection {
|
||||||
// Check if this has shutdown
|
// Check if this has shutdown
|
||||||
_ = canceller.cancelled() => break,
|
_ = canceller.cancelled() => break,
|
||||||
// Wait for the next message to send
|
// Wait for the next message to send
|
||||||
msg = internal_receiver.next() => {
|
Some(res) = internal_receiver.next() => {
|
||||||
if let Some(res) = msg {
|
|
||||||
// Send the message to the client
|
// Send the message to the client
|
||||||
if let Err(err) = sender.send(res).await {
|
if let Err(err) = sender.send(res).await {
|
||||||
// Output any errors if not a close error
|
// Output any errors if not a close error
|
||||||
|
@ -193,7 +192,6 @@ impl Connection {
|
||||||
// Exit out of the loop
|
// Exit out of the loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,11 +214,22 @@ impl Connection {
|
||||||
biased;
|
biased;
|
||||||
// Check if this has shutdown
|
// Check if this has shutdown
|
||||||
_ = canceller.cancelled() => break,
|
_ = canceller.cancelled() => break,
|
||||||
// Wait for the next message to read
|
// Remove any completed tasks
|
||||||
msg = receiver.next() => {
|
Some(out) = tasks.join_next() => match out {
|
||||||
if let Some(msg) = msg {
|
// The task completed successfully
|
||||||
// Process the received WebSocket message
|
Ok(_) => continue,
|
||||||
match msg {
|
// There was an uncaught panic in the task
|
||||||
|
Err(err) => {
|
||||||
|
// There was an error with the task
|
||||||
|
trace!("WebSocket request error: {:?}", err);
|
||||||
|
// Cancel the WebSocket tasks
|
||||||
|
rpc.read().await.canceller.cancel();
|
||||||
|
// Exit out of the loop
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Wait for the next received message
|
||||||
|
Some(msg) = receiver.next() => match msg {
|
||||||
// We've received a message from the client
|
// We've received a message from the client
|
||||||
Ok(msg) => match msg {
|
Ok(msg) => match msg {
|
||||||
Message::Text(_) => {
|
Message::Text(_) => {
|
||||||
|
@ -254,14 +263,15 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// Wait for all tasks to finish
|
// Wait for all tasks to finish
|
||||||
while let Some(res) = tasks.join_next().await {
|
while let Some(res) = tasks.join_next().await {
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
error!("Error while handling RPC message: {}", err);
|
// There was an error with the task
|
||||||
|
trace!("WebSocket request error: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Abort all tasks
|
||||||
|
tasks.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send live query notifications to the client
|
/// Send live query notifications to the client
|
||||||
|
|
Loading…
Reference in a new issue