Skip to content

Commit c61fcb8

Browse files
committed
fix(odbc): replace static ODBC environment with direct environment initialization
1 parent 8db5cd3 commit c61fcb8

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

sqlx-core/src/odbc/connection/worker.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::sync::OnceLock;
21
use std::thread;
32

43
use futures_channel::oneshot;
@@ -22,9 +21,6 @@ type ExecuteSender = flume::Sender<ExecuteResult>;
2221
type PrepareResult = Result<(u64, Vec<OdbcColumn>, usize), Error>;
2322
type PrepareSender = oneshot::Sender<PrepareResult>;
2423

25-
// Shared ODBC environment - initialized once, used by all connections
26-
static ODBC_ENV: OnceLock<&'static odbc_api::Environment> = OnceLock::new();
27-
2824
#[derive(Debug)]
2925
pub(crate) struct ConnectionWorker {
3026
command_tx: flume::Sender<Command>,
@@ -177,11 +173,7 @@ fn worker_thread_main(
177173
fn establish_connection(options: &OdbcConnectOptions) -> Result<OdbcConnection, Error> {
178174
// Get or create the shared ODBC environment
179175
// This ensures thread-safe initialization and prevents concurrent environment creation issues
180-
let env = ODBC_ENV.get_or_init(|| {
181-
Box::leak(Box::new(
182-
odbc_api::Environment::new().expect("Failed to create ODBC environment"),
183-
))
184-
});
176+
let env = odbc_api::environment().map_err(|e| Error::Configuration(e.to_string().into()))?;
185177

186178
let conn = env
187179
.connect_with_connection_string(options.connection_string(), Default::default())

0 commit comments

Comments
 (0)