Skip to content

Commit 52d983d

Browse files
committed
Thanks Code Rabbit
1 parent 7d4f65d commit 52d983d

File tree

8 files changed

+39
-24
lines changed

8 files changed

+39
-24
lines changed

components/frontend/src/dynamo/frontend/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def parse_args():
166166

167167
if flags.static_endpoint and (not flags.model_name or not flags.model_path):
168168
parser.error("--static-endpoint requires both --model-name and --model-path")
169+
if bool(flags.tls_cert_path) ^ bool(flags.tls_key_path): # ^ is XOR
170+
parser.error("--tls-cert-path and --tls-key-path must be provided together")
169171

170172
return flags
171173

launch/dynamo-run/src/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ pub struct Flags {
5050
pub http_port: u16,
5151

5252
/// TLS certificate file
53-
#[arg(long)]
53+
#[arg(long, requires = "tls_key_path")]
5454
pub tls_cert_path: Option<PathBuf>,
5555

5656
/// TLS certificate key file
57-
#[arg(long)]
57+
#[arg(long, requires = "tls_cert_path")]
5858
pub tls_key_path: Option<PathBuf>,
5959

6060
/// The name of the model we are serving

lib/bindings/python/Cargo.lock

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

lib/bindings/python/rust/llm/entrypoint.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use dynamo_llm::entrypoint::input::Input;
1010
use dynamo_llm::entrypoint::EngineConfig as RsEngineConfig;
1111
use dynamo_llm::entrypoint::RouterConfig as RsRouterConfig;
1212
use dynamo_llm::kv_router::KvRouterConfig as RsKvRouterConfig;
13+
use dynamo_llm::local_model::DEFAULT_HTTP_PORT;
1314
use dynamo_llm::local_model::{LocalModel, LocalModelBuilder};
1415
use dynamo_llm::mocker::protocols::MockEngineArgs;
1516
use dynamo_runtime::protocols::Endpoint as EndpointId;
@@ -128,6 +129,13 @@ impl EntrypointArgs {
128129
})?),
129130
None => None,
130131
};
132+
if (tls_cert_path.is_some() && tls_key_path.is_none())
133+
|| (tls_cert_path.is_none() && tls_key_path.is_some())
134+
{
135+
return Err(pyo3::exceptions::PyValueError::new_err(
136+
"tls_cert_path and tls_key_path must be provided together",
137+
));
138+
}
131139
Ok(EntrypointArgs {
132140
engine_type,
133141
model_path,
@@ -138,7 +146,7 @@ impl EntrypointArgs {
138146
template_file,
139147
router_config,
140148
kv_cache_block_size,
141-
http_port: http_port.unwrap_or(0),
149+
http_port: http_port.unwrap_or(DEFAULT_HTTP_PORT),
142150
tls_cert_path,
143151
tls_key_path,
144152
extra_engine_args,

lib/llm/src/entrypoint/input/http.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ pub async fn run(runtime: Runtime, engine_config: EngineConfig) -> anyhow::Resul
3737
.tls_key_path(Some(tls_key_path.to_path_buf()))
3838
.port(local_model.http_port())
3939
}
40-
(_, _) => service_v2::HttpService::builder().port(local_model.http_port()),
40+
(None, None) => service_v2::HttpService::builder().port(local_model.http_port()),
41+
(_, _) => {
42+
// CLI should prevent us ever getting here
43+
anyhow::bail!(
44+
"Both --tls-cert-path and --tls-key-path must be provided together to enable TLS"
45+
);
46+
}
4147
};
4248
http_service_builder =
4349
http_service_builder.with_request_template(engine_config.local_model().request_template());

lib/llm/src/http/service/service_v2.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl HttpService {
199199
pub async fn run(&self, cancel_token: CancellationToken) -> Result<()> {
200200
let address = format!("{}:{}", self.host, self.port);
201201
let protocol = if self.enable_tls { "HTTPS" } else { "HTTP" };
202-
tracing::info!(address, "Starting {protocol} service on: {address}");
202+
tracing::info!(protocol, address, "Starting HTTP(S) service");
203203

204204
let router = self.router.clone();
205205
let observer = cancel_token.child_token();
@@ -220,26 +220,27 @@ impl HttpService {
220220

221221
// aws_lc_rs is the default but other crates pull in `ring` also,
222222
// so rustls doesn't know which one to use. Tell it.
223-
let rustls_out = rustls::crypto::aws_lc_rs::default_provider().install_default();
224-
// The Err type is `Arc<Self>`. Very strange.
225-
if rustls_out.is_err() {
226-
anyhow::bail!(
227-
"Failed installing AWS-LC-RS as the TLS crypto provider. Cannot start web server."
228-
);
223+
if let Err(e) = rustls::crypto::aws_lc_rs::default_provider().install_default() {
224+
tracing::debug!("TLS crypto provider already installed: {e:?}");
229225
}
230226

231227
let config = RustlsConfig::from_pem_file(cert_path, key_path)
232228
.await
233229
.map_err(|e| anyhow::anyhow!("Failed to create TLS config: {}", e))?;
234230

235-
let server = axum_server::bind_rustls(addr, config).serve(router.into_make_service());
231+
let handle = axum_server::Handle::new();
232+
let server = axum_server::bind_rustls(addr, config)
233+
.handle(handle.clone())
234+
.serve(router.into_make_service());
236235

237236
tokio::select! {
238237
result = server => {
239238
result.map_err(|e| anyhow::anyhow!("HTTPS server error: {}", e))?;
240239
}
241240
_ = observer.cancelled() => {
242241
tracing::info!("HTTPS server shutdown requested");
242+
handle.graceful_shutdown(Some(Duration::from_secs(5)));
243+
// TODO: Do we need to wait?
243244
}
244245
}
245246
} else {

lib/llm/src/local_model.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const DEFAULT_NAME: &str = "dynamo";
3838
const DEFAULT_KV_CACHE_BLOCK_SIZE: u32 = 16;
3939

4040
/// We can't have it default to 0, so pick something
41-
const DEFAULT_HTTP_PORT: u16 = 8080;
41+
/// 'pub' because the bindings use it for consistency.
42+
pub const DEFAULT_HTTP_PORT: u16 = 8080;
4243

4344
pub struct LocalModelBuilder {
4445
model_path: Option<PathBuf>,

lib/runtime/src/component.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,11 @@ impl Component {
276276
let component_clone = self.clone();
277277
let mut hierarchies = self.parent_hierarchy();
278278
hierarchies.push(self.hierarchy());
279-
debug_assert_eq!(
280-
hierarchies
281-
.last()
282-
.cloned()
283-
.unwrap_or_default()
284-
.to_lowercase(),
285-
self.service_name().to_lowercase()
286-
); // it happens that in component, hierarchy and service name are the same
279+
debug_assert!(hierarchies
280+
.last()
281+
.map(|x| x.as_str())
282+
.unwrap_or_default()
283+
.eq_ignore_ascii_case(&self.service_name())); // it happens that in component, hierarchy and service name are the same
287284

288285
// Register a metrics callback that scrapes component statistics
289286
let metrics_callback = Arc::new(move || {

0 commit comments

Comments
 (0)