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

fix(test): fix CLI shutdown #1299

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions rust/src/bin/mina-indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use mina_indexer::{
initialize_indexer_database, start_indexer, IndexerConfiguration, InitializationMode,
},
store::{restore_snapshot, version::IndexerStoreVersion, IndexerStore},
unix_socket_server::remove_unix_socket,
web::start_web_server,
};
use std::{
Expand Down Expand Up @@ -287,7 +288,7 @@ impl ServerCommand {
check_or_write_pid_file(&database_dir);

debug!("Building mina indexer configuration");
let config = process_indexer_configuration(args, mode, domain_socket_path)?;
let config = process_indexer_configuration(args, mode, domain_socket_path.clone())?;

debug!("Creating a new mina indexer database in {database_dir:#?}");
let db = Arc::new(IndexerStore::new(&database_dir)?);
Expand All @@ -302,11 +303,12 @@ impl ServerCommand {
start_web_server(s, store, (web_hostname, web_port))
}));

info!("Shutting down primary database instance");
subsys.on_shutdown_requested().await;
info!("Shutting down primary database instance");
db.database.cancel_all_background_work(true);
remove_pid(&database_dir);
drop(db);
remove_unix_socket(&domain_socket_path)?;
Ok(())
}
}
Expand Down
1 change: 0 additions & 1 deletion rust/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ pub async fn start_indexer(
)
.await?;

subsys.on_shutdown_requested().await;
Ok(())
}

Expand Down
9 changes: 1 addition & 8 deletions rust/src/unix_socket_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pub async fn handle_connection(
bail!("Unable to get a handle on indexer store...");
};

let local_addr = &connection.local_addr()?;
let command = parse_conn_to_cli(&connection).await?;
let (_, mut writer) = connection.into_split();

Expand Down Expand Up @@ -978,12 +977,6 @@ pub async fn handle_connection(
.write_all(b"Shutting down the Mina Indexer daemon...")
.await?;
subsys.request_shutdown();
remove_unix_socket(
local_addr
.as_pathname()
.expect("Unable to locate Unix domain socket file"),
)
.expect("Unix domain socket file deleted");
return Ok(());
}
ClientCli::Summary {
Expand Down Expand Up @@ -1242,7 +1235,7 @@ fn try_replace_old_socket(e: io::Error, unix_socket_path: &Path) -> io::Result<U
}
}

fn remove_unix_socket(unix_socket_path: &Path) -> io::Result<()> {
pub fn remove_unix_socket(unix_socket_path: &Path) -> io::Result<()> {
std::fs::remove_file(unix_socket_path)?;
debug!("Removed Unix domain socket: {:?}", unix_socket_path);
Ok(())
Expand Down
15 changes: 7 additions & 8 deletions tests/regression.bash
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ wait_forever_for_socket() {
}

idxr_server() {
idxr server "$@" &
RUST_BACKTRACE=full "$IDXR" --socket ./mina-indexer.sock server "$@" &
echo $! > ./idxr_pid
}

Expand Down Expand Up @@ -1384,8 +1384,8 @@ test_clean_kill() {
return 1
fi

echo " Sending Mina Indexer a SIGTERM"
PID="$(cat ./idxr_pid)"
echo " Sending Mina Indexer (PID $PID) a SIGTERM"
kill "$PID"

# We must give the process a chance to die cleanly.
Expand All @@ -1402,12 +1402,11 @@ test_clean_kill() {
return 1
fi

# TODO: robinbb - this is commented out because it does not pass!
# # Check for socket deletion.
# if [ -S ./mina-indexer.sock ]; then
# echo " The signal handler did not delete the socket. Failure."
# return 1
# fi
# Check for socket deletion.
if [ -S ./mina-indexer.sock ]; then
echo " The signal handler did not delete the socket. Failure."
return 1
fi
}

test_block_children() {
Expand Down