mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Fix net server stopping when handle is garbage collected
This commit is contained in:
parent
a86a62ae1f
commit
fbee7c85bd
4 changed files with 26 additions and 2 deletions
|
@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Fixed
|
||||
|
||||
- Fixed `net.serve` stopping when the returned `ServeHandle` is garbage collected
|
||||
- Fixed missing trailing newline when using the `warn` global
|
||||
- Fixed constructor for `CFrame` in the `roblox` built-in library not parsing the 12-arg overload correctly. ([#102])
|
||||
- Fixed various functions for `CFrame` in the `roblox` built-in library being incorrect, specifically row-column ordering and some flipped signs. ([#103])
|
||||
|
|
|
@ -12,7 +12,7 @@ use tokio::sync::{mpsc, oneshot, Mutex};
|
|||
|
||||
use crate::lune::{
|
||||
scheduler::Scheduler,
|
||||
util::{traits::LuaEmitErrorExt, TableBuilder},
|
||||
util::{futures::yield_forever, traits::LuaEmitErrorExt, TableBuilder},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -115,7 +115,11 @@ where
|
|||
.http1_keepalive(true) // Web sockets must be kept alive
|
||||
.serve(hyper_make_service)
|
||||
.with_graceful_shutdown(async move {
|
||||
shutdown_rx.recv().await;
|
||||
if shutdown_rx.recv().await.is_none() {
|
||||
// The channel was closed, meaning the serve handle
|
||||
// was garbage collected by lua without being used
|
||||
yield_forever().await;
|
||||
}
|
||||
});
|
||||
if let Err(e) = result.await {
|
||||
eprintln!("Net serve error: {e}")
|
||||
|
|
18
src/lune/util/futures.rs
Normal file
18
src/lune/util/futures.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct YieldForever;
|
||||
|
||||
impl Future for YieldForever {
|
||||
type Output = ();
|
||||
|
||||
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
||||
pub fn yield_forever() -> YieldForever {
|
||||
YieldForever
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
mod table_builder;
|
||||
|
||||
pub mod formatting;
|
||||
pub mod futures;
|
||||
pub mod traits;
|
||||
|
||||
pub use table_builder::TableBuilder;
|
||||
|
|
Loading…
Reference in a new issue