Skip to content

Commit 2a688c4

Browse files
committed
Exit gracefully if any servers exited, bump version to v1.7.0-alpha.12
1 parent be3a21d commit 2a688c4

File tree

5 files changed

+42
-59
lines changed

5 files changed

+42
-59
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "shadowsocks-rust"
3-
version = "1.7.0-alpha.11"
3+
version = "1.7.0-alpha.12"
44
authors = ["Y. T. CHUNG <zonyitoo@gmail.com>"]
55
description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls."
66
repository = "https://github.com/zonyitoo/shadowsocks-rust"

src/bin/local.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use clap::{App, Arg};
1919
use std::env;
2020
use std::io::{self, Write};
2121
use std::net::SocketAddr;
22-
use std::process;
2322

2423
use env_logger::fmt::Formatter;
2524
use env_logger::Builder;
2625
use futures::Future;
2726
use log::{LevelFilter, Record};
27+
use tokio::runtime::Runtime;
2828

2929
use shadowsocks::plugin::PluginConfig;
3030
use shadowsocks::{run_local, Config, ConfigType, ServerAddr, ServerConfig};
@@ -235,16 +235,11 @@ fn main() {
235235

236236
debug!("Config: {:?}", config);
237237

238-
tokio::run(run_local(config).then(|res| -> Result<(), ()> {
239-
match res {
240-
Ok(..) => error!("Server exited without error"),
241-
Err(err) => error!("Server exited with error: {}", err),
242-
}
243-
244-
// Kill the whole process
245-
// Otherwise the users on this crashed server won't be able to connect
246-
// until manually restart the server.
247-
// Just crash and restart.
248-
process::exit(1);
249-
}));
238+
let mut runtime = Runtime::new().expect("Creating runtime");
239+
240+
let result = runtime.block_on(run_local(config));
241+
242+
runtime.shutdown_now().wait().unwrap();
243+
244+
panic!("Server exited unexpectly with result: {:?}", result);
250245
}

src/bin/server.rs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ extern crate tokio;
1818

1919
use std::env;
2020
use std::io::{self, Write};
21-
use std::process;
2221

2322
use clap::{App, Arg};
2423

2524
use env_logger::fmt::Formatter;
2625
use env_logger::Builder;
2726
use futures::Future;
2827
use log::{LevelFilter, Record};
28+
use tokio::runtime::Runtime;
2929

3030
use shadowsocks::plugin::PluginConfig;
3131
use shadowsocks::{run_server, Config, ConfigType, ServerAddr, ServerConfig};
@@ -133,18 +133,16 @@ fn main() {
133133

134134
let mut has_provided_config = false;
135135
let mut config = match matches.value_of("CONFIG") {
136-
Some(cpath) => {
137-
match Config::load_from_file(cpath, ConfigType::Server) {
138-
Ok(cfg) => {
139-
has_provided_config = true;
140-
cfg
141-
}
142-
Err(err) => {
143-
error!("{:?}", err);
144-
return;
145-
}
136+
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Server) {
137+
Ok(cfg) => {
138+
has_provided_config = true;
139+
cfg
146140
}
147-
}
141+
Err(err) => {
142+
error!("{:?}", err);
143+
return;
144+
}
145+
},
148146
None => Config::new(),
149147
};
150148

@@ -198,16 +196,11 @@ fn main() {
198196

199197
debug!("Config: {:?}", config);
200198

201-
tokio::run(run_server(config).then(|res| -> Result<(), ()> {
202-
match res {
203-
Ok(..) => error!("Server exited without error"),
204-
Err(err) => error!("Server exited with error: {}", err),
205-
}
206-
207-
// Kill the whole process
208-
// Otherwise the users on this crashed server won't be able to connect
209-
// until manually restart the server.
210-
// Just crash and restart.
211-
process::exit(1);
212-
}));
199+
let mut runtime = Runtime::new().expect("Creating runtime");
200+
201+
let result = runtime.block_on(run_server(config));
202+
203+
runtime.shutdown_now().wait().unwrap();
204+
205+
panic!("Server exited unexpectly with result: {:?}", result);
213206
}

src/bin/ssdns.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use clap::{App, Arg};
1414
use std::env;
1515
use std::io::{self, Write};
1616
use std::net::SocketAddr;
17-
use std::process;
1817

1918
use env_logger::fmt::Formatter;
2019
use env_logger::Builder;
2120
use futures::Future;
2221
use log::{LevelFilter, Record};
22+
use tokio::runtime::Runtime;
2323

2424
use shadowsocks::{run_dns, Config, ConfigType, ServerAddr, ServerConfig};
2525

@@ -215,16 +215,11 @@ fn main() {
215215

216216
debug!("Config: {:?}", config);
217217

218-
tokio::run(run_dns(config).then(|res| -> Result<(), ()> {
219-
match res {
220-
Ok(..) => error!("Server exited without error"),
221-
Err(err) => error!("Server exited with error: {}", err),
222-
}
223-
224-
// Kill the whole process
225-
// Otherwise the users on this crashed server won't be able to connect
226-
// until manually restart the server.
227-
// Just crash and restart.
228-
process::exit(1);
229-
}));
218+
let mut runtime = Runtime::new().expect("Creating runtime");
219+
220+
let result = runtime.block_on(run_dns(config));
221+
222+
runtime.shutdown_now().wait().unwrap();
223+
224+
panic!("Server exited unexpectly with result: {:?}", result);
230225
}

0 commit comments

Comments
 (0)