Skip to content

Commit

Permalink
peerdb-server: receive sigint & exit (#706)
Browse files Browse the repository at this point in the history
Does not gracefully shutdown all sockets. To do that we'd need to store
the sockets from listen to a map & shutdown. But all the programs we're
interfacing with should be handling connection being dropped suddenly

Fixes #682
  • Loading branch information
serprex authored Nov 23, 2023
1 parent 4b1447b commit bf8db46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ services:

peerdb:
container_name: peerdb-server
stop_signal: SIGINT
build:
context: .
dockerfile: stacks/peerdb-server.Dockerfile
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ services:

peerdb:
container_name: peerdb-server
stop_signal: SIGINT
image: ghcr.io/peerdb-io/peerdb-server:latest-dev
environment:
<<: *catalog-config
Expand Down
8 changes: 7 additions & 1 deletion nexus/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use pt::{
peerdb_peers::{peer::Config, Peer},
};
use rand::Rng;
use tokio::signal::unix::{signal, SignalKind};
use tokio::sync::{Mutex, MutexGuard};
use tokio::{io::AsyncWriteExt, net::TcpListener};
use tracing_appender::non_blocking::WorkerGuard;
Expand Down Expand Up @@ -1371,8 +1372,13 @@ pub async fn main() -> anyhow::Result<()> {
None
};

let mut sigintstream = signal(SignalKind::interrupt()).expect("Failed to setup signal handler");
loop {
let (mut socket, _) = listener.accept().await.unwrap();
let (mut socket, _) = tokio::select! {
_ = sigintstream.recv() => return Ok(()),
v = listener.accept() => v,
}
.unwrap();
let catalog = match Catalog::new(&catalog_config).await {
Ok(c) => c,
Err(e) => {
Expand Down

0 comments on commit bf8db46

Please sign in to comment.