Skip to content

Commit

Permalink
fix(serve): don't break socket listening loop on connect error (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jul 14, 2024
1 parent 254d9aa commit 7bda02f
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/serve/o7s_unix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use log::{debug, warn};
use pallas::network::facades::NodeServer;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tokio::net::UnixListener;
use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;
use tracing::{info, instrument};
use tracing::{debug, info, instrument, warn};

use crate::prelude::*;
use crate::wal::redb::WalStore;
Expand Down Expand Up @@ -49,22 +48,26 @@ async fn accept_client_connections(
cancel: CancellationToken,
) -> Result<(), Error> {
let listener = UnixListener::bind(&config.listen_path).map_err(Error::server)?;
info!(addr = %config.listen_path.to_string_lossy(), "Ouroboros socket is listenting");
info!(addr = %config.listen_path.to_string_lossy(), "Ouroboros socket is listening for clients");

loop {
let connection = NodeServer::accept(&listener, config.magic)
.await
.map_err(Error::server)?;

info!(
from = ?connection.accepted_address(),
handshake = ?connection.accepted_version(),
"accepting incoming connection"
);

tasks.spawn(handle_session(wal.clone(), connection, cancel.clone()));

info!(connections = tasks.len(), "active connections changed");
let connection = NodeServer::accept(&listener, config.magic).await;

match connection {
Ok(connection) => {
info!(
from = ?connection.accepted_address(),
handshake = ?connection.accepted_version(),
"accepting incoming connection"
);

tasks.spawn(handle_session(wal.clone(), connection, cancel.clone()));
info!(connections = tasks.len(), "active connections changed");
}
Err(error) => {
warn!(%error, "error on incoming connection");
}
}
}
}

Expand Down

0 comments on commit 7bda02f

Please sign in to comment.