Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 pd: fix auto-https default grpc address #3650

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![allow(clippy::clone_on_copy)]
#![deny(clippy::unwrap_used)]
#![recursion_limit = "512"]
use std::{net::SocketAddr, path::PathBuf};
use std::{error::Error, net::SocketAddr, path::PathBuf};

use console_subscriber::ConsoleLayer;
use metrics_tracing_context::{MetricsLayer, TracingContextLayer};
use metrics_util::layers::Stack;
use std::error::Error;

use anyhow::Context;
use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -283,21 +282,22 @@ async fn main() -> anyhow::Result<()> {
cometbft_addr,
enable_expensive_rpc,
} => {
// Unpack grpc bind option, defaulting to localhost, but setting 0.0.0.0:443
// if auto https is enabled. We unpack the option outside of the conditional
// below, in order to report the bind address in error handling.
let grpc_bind = if grpc_bind.is_some() {
grpc_bind.unwrap_or(
"0.0.0.0:443"
.parse()
.context("failed to parse grpc_bind address")?,
)
} else {
grpc_bind.unwrap_or(
"127.0.0.1:8080"
.parse()
.context("failed to parse grpc_bind address")?,
)
// Use the given `grpc_bind` address if one was specified. If not, we will choose a
// default depending on whether or not `grpc_auto_https` was set. See the
// `RootCommand::Start::grpc_bind` documentation above.
let grpc_bind = {
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
const HTTP_DEFAULT: SocketAddr =
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
const HTTPS_DEFAULT: SocketAddr =
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 443);
let default = || {
grpc_auto_https
.is_some()
.then_some(HTTPS_DEFAULT)
.unwrap_or(HTTP_DEFAULT)
};
grpc_bind.unwrap_or_else(default)
};

// Ensure we have all necessary parts in the URL
Expand Down
Loading