You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by "jadireddi (via GitHub)" <gi...@apache.org> on 2025/08/25 20:50:12 UTC
[PR] fix(server): Update TCP TLS server with compio. [iggy]
jadireddi opened a new pull request, #2130:
URL: https://github.com/apache/iggy/pull/2130
Fixes: https://github.com/apache/iggy/issues/1936
Migrates the TCP TLS listener and sender from tokio based `tokio-tls` with `compio-tls` to align with the project's io_uring migration strategy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(server): Update TCP TLS server with compio. [iggy]
Posted by "numinnex (via GitHub)" <gi...@apache.org>.
numinnex commented on code in PR #2130:
URL: https://github.com/apache/iggy/pull/2130#discussion_r2300172001
##########
core/server/src/tcp/tcp_tls_listener.rs:
##########
@@ -17,48 +17,126 @@
*/
use crate::binary::sender::SenderKind;
-use crate::configs::tcp::TcpTlsConfig;
-use crate::io::storage::Storage;
+use crate::configs::tcp::TcpSocketConfig;
use crate::shard::IggyShard;
use crate::shard::transmission::event::ShardEvent;
use crate::streaming::clients::client_manager::Transport;
use crate::tcp::connection_handler::{handle_connection, handle_error};
+use crate::{shard_error, shard_info, shard_warn};
+use compio::net::{TcpListener, TcpOpts};
+use compio_tls::TlsAcceptor;
+use error_set::ErrContext;
use futures::FutureExt;
use iggy_common::IggyError;
use rustls::ServerConfig;
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
use rustls_pemfile::{certs, private_key};
-use socket2::Socket;
use std::io::BufReader;
use std::net::SocketAddr;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Duration;
-use tracing::{error, info};
+use tracing::trace;
pub(crate) async fn start(
server_name: &'static str,
- addr: SocketAddr,
- socket: Socket,
+ mut addr: SocketAddr,
+ config: &TcpSocketConfig,
shard: Rc<IggyShard>,
) -> Result<(), IggyError> {
- /*
- let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
- let config = &shard.config.tcp.tls;
-
- let (certs, key) =
- if config.self_signed && !std::path::Path::new(&config.cert_file).exists() {
- info!("Generating self-signed certificate for TCP TLS server");
- generate_self_signed_cert()
- .unwrap_or_else(|e| panic!("Failed to generate self-signed certificate: {e}"))
- } else {
- info!(
- "Loading certificates from cert_file: {}, key_file: {}",
- config.cert_file, config.key_file
- );
- load_certificates(&config.cert_file, &config.key_file)
- .unwrap_or_else(|e| panic!("Failed to load certificates: {e}"))
+ //TODO: Fix me, this needs to take into account that first shard id potentially can be greater than 0.
+ if shard.id != 0 && addr.port() == 0 {
+ shard_info!(shard.id, "Waiting for TCP address from shard 0...");
+ loop {
+ if let Some(bound_addr) = shard.tcp_bound_address.get() {
+ addr = bound_addr;
+ shard_info!(shard.id, "Received TCP address: {}", addr);
+ break;
+ }
+ compio::time::sleep(Duration::from_millis(10)).await;
+ }
+ }
+
+ let listener = create_listener(addr, config)
+ .await
+ .map_err(|_| IggyError::CannotBindToSocket(addr.to_string()))
+ .with_error_context(|err| {
+ format!("Failed to bind {server_name} server to address: {addr}, {err}")
+ })?;
+
+ let actual_addr = listener.local_addr().map_err(|_e| {
+ shard_error!(shard.id, "Failed to get local address: {_e}");
+ IggyError::CannotBindToSocket(addr.to_string())
+ })?;
+
+ //TODO: Fix me, this needs to take into account that first shard id potentially can be greater than 0.
+ if shard.id == 0 {
+ if addr.port() == 0 {
+ let event = ShardEvent::TcpBound {
+ address: actual_addr,
};
+ shard.broadcast_event_to_all_shards(event).await;
+ }
+
+ let mut current_config = shard.config.clone();
+ current_config.tcp.address = actual_addr.to_string();
+
+ let runtime_path = current_config.system.get_runtime_path();
+ let current_config_path = format!("{runtime_path}/current_config.toml");
+ let current_config_content =
+ toml::to_string(¤t_config).expect("Cannot serialize current_config");
+
+ let buf_result = compio::fs::write(¤t_config_path, current_config_content).await;
+ match buf_result.0 {
+ Ok(_) => shard_info!(
+ shard.id,
+ "Current config written to: {}",
+ current_config_path
+ ),
+ Err(e) => shard_error!(
+ shard.id,
+ "Failed to write current config to {}: {}",
+ current_config_path,
+ e
+ ),
+ }
+ }
+
+ // Ensure rustls crypto provider is installed
+ if rustls::crypto::CryptoProvider::get_default().is_none() {
Review Comment:
You can use if let chains to reduce the nesting,
```rs
if rustls::crypto::CryptoProvider::get_default().is_none() && let Err(e) = rustls::crypto::ring::default_provider().install_default() {
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(server): Update TCP TLS server with compio. [iggy]
Posted by "numinnex (via GitHub)" <gi...@apache.org>.
numinnex merged PR #2130:
URL: https://github.com/apache/iggy/pull/2130
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@iggy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org