Skip to content

Commit 6f42942

Browse files
feat(router): add argument for hostname in router (#545) (#550)
# What does this PR do? In title. Adds argument `--hostname` in router to support something like `--hostname ::`. Tested with ```commandline cargo run -- --port 8080 --hostname :: curl -I -X GET 'http://[::1]:8080/health' # failed before this commit ``` Trigger CI --------- Co-authored-by: Phil Chen <[email protected]>
1 parent 31e2253 commit 6f42942

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

launcher/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ struct Args {
197197
#[clap(default_value = "20", long, env)]
198198
max_waiting_tokens: usize,
199199

200+
/// The IP address to listen on
201+
#[clap(default_value = "0.0.0.0", long, env)]
202+
hostname: String,
203+
200204
/// The port to listen on.
201205
#[clap(default_value = "3000", long, short, env)]
202206
port: u16,
@@ -874,6 +878,8 @@ fn spawn_webserver(
874878
args.waiting_served_ratio.to_string(),
875879
"--max-waiting-tokens".to_string(),
876880
args.max_waiting_tokens.to_string(),
881+
"--hostname".to_string(),
882+
args.hostname.to_string(),
877883
"--port".to_string(),
878884
args.port.to_string(),
879885
"--master-shard-uds-path".to_string(),

router/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct Args {
4040
max_batch_total_tokens: u32,
4141
#[clap(default_value = "20", long, env)]
4242
max_waiting_tokens: usize,
43+
#[clap(default_value = "0.0.0.0", long, env)]
44+
hostname: String,
4345
#[clap(default_value = "3000", long, short, env)]
4446
port: u16,
4547
#[clap(default_value = "/tmp/text-generation-server-0", long, env)]
@@ -82,6 +84,7 @@ fn main() -> Result<(), std::io::Error> {
8284
max_batch_prefill_tokens,
8385
max_batch_total_tokens,
8486
max_waiting_tokens,
87+
hostname,
8588
port,
8689
master_shard_uds_path,
8790
tokenizer_name,
@@ -213,8 +216,13 @@ fn main() -> Result<(), std::io::Error> {
213216
.expect("Unable to warmup model");
214217
tracing::info!("Connected");
215218

216-
// Binds on localhost
217-
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port);
219+
let addr = match hostname.parse() {
220+
Ok(ip) => SocketAddr::new(ip, port),
221+
Err(_) => {
222+
tracing::warn!("Invalid hostname, defaulting to 0.0.0.0");
223+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port)
224+
}
225+
};
218226

219227
// Run server
220228
server::run(

0 commit comments

Comments
 (0)