File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
sqlx-core/src/odbc/connection Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,10 @@ impl Connection for OdbcConnection {
6464 false
6565 }
6666}
67+
68+ impl Drop for OdbcConnection {
69+ fn drop ( & mut self ) {
70+ // Send shutdown command to worker thread to prevent resource leak
71+ self . worker . shutdown_sync ( ) ;
72+ }
73+ }
Original file line number Diff line number Diff line change @@ -80,6 +80,16 @@ impl ConnectionWorker {
8080 send_command_and_await ( & self . command_tx , Command :: Shutdown { tx } , rx) . await
8181 }
8282
83+ pub ( crate ) fn shutdown_sync ( & mut self ) {
84+ // Send shutdown command without waiting for response
85+ // Use try_send to avoid any potential blocking in Drop
86+ let ( tx, _rx) = oneshot:: channel ( ) ;
87+ let _ = self . command_tx . try_send ( Command :: Shutdown { tx } ) ;
88+
89+ // Don't aggressively drop the channel to avoid SendError panics
90+ // The worker thread will exit when it processes the Shutdown command
91+ }
92+
8393 pub ( crate ) async fn begin ( & mut self ) -> Result < ( ) , Error > {
8494 let ( tx, rx) = oneshot:: channel ( ) ;
8595 send_transaction_command ( & self . command_tx , Command :: Begin { tx } , rx) . await
@@ -156,11 +166,12 @@ fn worker_thread_main(
156166 }
157167
158168 // Process commands
159- for cmd in rx {
169+ while let Ok ( cmd) = rx. recv ( ) {
160170 if !process_command ( cmd, & conn) {
161171 break ;
162172 }
163173 }
174+ // Channel disconnected or shutdown command received, worker thread exits
164175}
165176
166177fn establish_connection ( options : & OdbcConnectOptions ) -> Result < OdbcConnection , Error > {
You can’t perform that action at this time.
0 commit comments