Skip to main content

shutdown

Function shutdown 

Source
pub fn shutdown() -> Result<()>
Expand description

Stop the engine, joining every thread chDB started.

Call this before a host teardown sequence of its own — global destructors, a finalizing language runtime, a sanitizer exit handler — which would otherwise race the engine’s still-running threads.

A plain exit needs care too. Exiting with a connection still open leaves the engine to be torn down from inside exit, and if MergeTree merges are running in the background at that point the process can crash on its way out. Drop every connection before the process exits, and call this after the last one is gone: it returns only once no chDB thread is left. Two common ways a Rust program keeps a connection open at exit: std::process::exit runs no destructors, and a connection held in a static is never dropped.

This is one-way. Once it succeeds, no further connection can be opened in this process. Calling it again is harmless.

§Errors

Returns Error::ConnectionsStillOpen if any connection is open, and Error::EngineCallFailed if the engine could not stop every thread. In the latter case chdb.h documents the engine as closed for the process regardless — “whether or not it manages to stop every thread” — so this error means the engine is already shut down even though it is reported as a failure; the crate’s internal shut-down flag is not set for it (see SHUT_DOWN), so a subsequent open() will surface ConnectionFailed rather than Error::EngineShutDown.

§Examples

let conn = chdb_rust::connection::Connection::open_in_memory()?;
drop(conn);
chdb_rust::runtime::shutdown()?;