Fix net server stopping when handle is garbage collected

This commit is contained in:
Filip Tibell 2023-09-25 12:32:57 -05:00
parent a86a62ae1f
commit fbee7c85bd
No known key found for this signature in database
4 changed files with 26 additions and 2 deletions

View file

@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed `net.serve` stopping when the returned `ServeHandle` is garbage collected
- Fixed missing trailing newline when using the `warn` global - 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 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]) - Fixed various functions for `CFrame` in the `roblox` built-in library being incorrect, specifically row-column ordering and some flipped signs. ([#103])

View file

@ -12,7 +12,7 @@ use tokio::sync::{mpsc, oneshot, Mutex};
use crate::lune::{ use crate::lune::{
scheduler::Scheduler, scheduler::Scheduler,
util::{traits::LuaEmitErrorExt, TableBuilder}, util::{futures::yield_forever, traits::LuaEmitErrorExt, TableBuilder},
}; };
use super::{ use super::{
@ -115,7 +115,11 @@ where
.http1_keepalive(true) // Web sockets must be kept alive .http1_keepalive(true) // Web sockets must be kept alive
.serve(hyper_make_service) .serve(hyper_make_service)
.with_graceful_shutdown(async move { .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 { if let Err(e) = result.await {
eprintln!("Net serve error: {e}") eprintln!("Net serve error: {e}")

18
src/lune/util/futures.rs Normal file
View 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
}

View file

@ -1,6 +1,7 @@
mod table_builder; mod table_builder;
pub mod formatting; pub mod formatting;
pub mod futures;
pub mod traits; pub mod traits;
pub use table_builder::TableBuilder; pub use table_builder::TableBuilder;