mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 11:31:09 +00:00
Fix test server listener thread leak (#655)
This commit is contained in:
parent
4f2e970732
commit
e5cdd22720
2 changed files with 17 additions and 7 deletions
|
@ -12,6 +12,8 @@
|
|||
|
||||
* StaticFiles decode special characters in request's path
|
||||
|
||||
* Fix test server listener leak #654
|
||||
|
||||
## [0.7.17] - 2018-12-25
|
||||
|
||||
### Added
|
||||
|
|
22
src/test.rs
22
src/test.rs
|
@ -5,7 +5,9 @@ use std::sync::mpsc;
|
|||
use std::{net, thread};
|
||||
|
||||
use actix::{Actor, Addr, System};
|
||||
use actix::actors::signal;
|
||||
|
||||
use actix_net::server::Server;
|
||||
use cookie::Cookie;
|
||||
use futures::Future;
|
||||
use http::header::HeaderName;
|
||||
|
@ -66,6 +68,7 @@ pub struct TestServer {
|
|||
ssl: bool,
|
||||
conn: Addr<ClientConnector>,
|
||||
rt: Runtime,
|
||||
backend: Addr<Server>,
|
||||
}
|
||||
|
||||
impl TestServer {
|
||||
|
@ -112,24 +115,25 @@ impl TestServer {
|
|||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
|
||||
let _ = HttpServer::new(factory)
|
||||
let srv = HttpServer::new(factory)
|
||||
.disable_signals()
|
||||
.listen(tcp)
|
||||
.keep_alive(5)
|
||||
.start();
|
||||
|
||||
tx.send((System::current(), local_addr, TestServer::get_conn()))
|
||||
tx.send((System::current(), local_addr, TestServer::get_conn(), srv))
|
||||
.unwrap();
|
||||
sys.run();
|
||||
});
|
||||
|
||||
let (system, addr, conn) = rx.recv().unwrap();
|
||||
let (system, addr, conn, backend) = rx.recv().unwrap();
|
||||
System::set_current(system);
|
||||
TestServer {
|
||||
addr,
|
||||
conn,
|
||||
ssl: false,
|
||||
rt: Runtime::new().unwrap(),
|
||||
backend,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,6 +201,7 @@ impl TestServer {
|
|||
|
||||
/// Stop http server
|
||||
fn stop(&mut self) {
|
||||
let _ = self.backend.send(signal::Signal(signal::SignalType::Term)).wait();
|
||||
System::current().stop();
|
||||
}
|
||||
|
||||
|
@ -333,8 +338,7 @@ where
|
|||
.keep_alive(5)
|
||||
.disable_signals();
|
||||
|
||||
tx.send((System::current(), addr, TestServer::get_conn()))
|
||||
.unwrap();
|
||||
|
||||
|
||||
#[cfg(any(feature = "alpn", feature = "ssl"))]
|
||||
{
|
||||
|
@ -356,18 +360,22 @@ where
|
|||
let tcp = net::TcpListener::bind(addr).unwrap();
|
||||
srv = srv.listen(tcp);
|
||||
}
|
||||
srv.start();
|
||||
let backend = srv.start();
|
||||
|
||||
tx.send((System::current(), addr, TestServer::get_conn(), backend))
|
||||
.unwrap();
|
||||
|
||||
sys.run();
|
||||
});
|
||||
|
||||
let (system, addr, conn) = rx.recv().unwrap();
|
||||
let (system, addr, conn, backend) = rx.recv().unwrap();
|
||||
System::set_current(system);
|
||||
TestServer {
|
||||
addr,
|
||||
conn,
|
||||
ssl: has_ssl,
|
||||
rt: Runtime::new().unwrap(),
|
||||
backend,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue