mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
This reverts commit 4a09fed36c
.
This commit is contained in:
parent
0acf380320
commit
25d93c8606
2 changed files with 14 additions and 22 deletions
|
@ -30,7 +30,6 @@ use rustls::internal::pemfile;
|
|||
use std::convert::Infallible;
|
||||
use std::fmt::{self, Display};
|
||||
use std::fs::File;
|
||||
use std::mem;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::{io, thread};
|
||||
|
@ -200,26 +199,25 @@ impl ApiServer {
|
|||
addr: SocketAddr,
|
||||
router: Router,
|
||||
) -> Result<thread::JoinHandle<()>, Error> {
|
||||
if self.is_running() {
|
||||
if self.shutdown_sender.is_some() {
|
||||
return Err(ErrorKind::Internal(
|
||||
"Can't start HTTP API server, it's running already".to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
let (tx, rx) = oneshot::channel::<()>();
|
||||
let (tx, _rx) = oneshot::channel::<()>();
|
||||
self.shutdown_sender = Some(tx);
|
||||
thread::Builder::new()
|
||||
.name("apis".to_string())
|
||||
.spawn(move || {
|
||||
let server = async move {
|
||||
let server = Server::bind(&addr)
|
||||
.serve(make_service_fn(move |_| {
|
||||
let router = router.clone();
|
||||
async move { Ok::<_, Infallible>(router) }
|
||||
}))
|
||||
.with_graceful_shutdown(async {
|
||||
rx.await.ok();
|
||||
});
|
||||
let server = Server::bind(&addr).serve(make_service_fn(move |_| {
|
||||
let router = router.clone();
|
||||
async move { Ok::<_, Infallible>(router) }
|
||||
}));
|
||||
// TODO graceful shutdown is unstable, investigate
|
||||
//.with_graceful_shutdown(rx)
|
||||
|
||||
server.await
|
||||
};
|
||||
|
||||
|
@ -241,7 +239,7 @@ impl ApiServer {
|
|||
router: Router,
|
||||
conf: TLSConfig,
|
||||
) -> Result<thread::JoinHandle<()>, Error> {
|
||||
if self.is_running() {
|
||||
if self.shutdown_sender.is_some() {
|
||||
return Err(ErrorKind::Internal(
|
||||
"Can't start HTTPS API server, it's running already".to_string(),
|
||||
)
|
||||
|
@ -282,9 +280,10 @@ impl ApiServer {
|
|||
|
||||
/// Stops the API server, it panics in case of error
|
||||
pub fn stop(&mut self) -> bool {
|
||||
if self.is_running() {
|
||||
let tx = mem::replace(&mut self.shutdown_sender, None).unwrap();
|
||||
tx.send(()).expect("Failed to stop API server");
|
||||
if self.shutdown_sender.is_some() {
|
||||
// TODO re-enable stop after investigation
|
||||
//let tx = mem::replace(&mut self.shutdown_sender, None).unwrap();
|
||||
//tx.send(()).expect("Failed to stop API server");
|
||||
info!("API server has been stopped");
|
||||
true
|
||||
} else {
|
||||
|
@ -292,10 +291,6 @@ impl ApiServer {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.shutdown_sender.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LoggingMiddleware {}
|
||||
|
|
|
@ -78,7 +78,6 @@ fn test_start_api() {
|
|||
assert_eq!(counter.value(), 1);
|
||||
assert!(server.stop());
|
||||
thread::sleep(time::Duration::from_millis(1_000));
|
||||
assert!(!server.is_running());
|
||||
}
|
||||
|
||||
// To enable this test you need a trusted PKCS12 (p12) certificate bundle
|
||||
|
@ -101,8 +100,6 @@ fn test_start_api_tls() {
|
|||
let index = request_with_retry("https://yourdomain.com:14444/v1/").unwrap();
|
||||
assert_eq!(index.len(), 2);
|
||||
assert!(!server.stop());
|
||||
thread::sleep(time::Duration::from_millis(1_000));
|
||||
assert!(!server.is_running());
|
||||
}
|
||||
|
||||
fn request_with_retry(url: &str) -> Result<Vec<String>, api::Error> {
|
||||
|
|
Loading…
Reference in a new issue