diff --git a/sqlx-sqlite/src/connection/establish.rs b/sqlx-sqlite/src/connection/establish.rs index 545bad747c..5a6a4267bf 100644 --- a/sqlx-sqlite/src/connection/establish.rs +++ b/sqlx-sqlite/src/connection/establish.rs @@ -48,6 +48,7 @@ pub struct EstablishParams { busy_timeout: Duration, statement_cache_capacity: usize, log_settings: LogSettings, + pub(crate) thread_stack_size: usize, extensions: IndexMap>, pub(crate) thread_name: String, pub(crate) command_channel_size: usize, @@ -159,6 +160,7 @@ impl EstablishParams { busy_timeout: options.busy_timeout, statement_cache_capacity: options.statement_cache_capacity, log_settings: options.log_settings.clone(), + thread_stack_size: options.thread_stack_size, extensions, thread_name: (options.thread_name)(thread_id as u64), command_channel_size: options.command_channel_size, diff --git a/sqlx-sqlite/src/connection/worker.rs b/sqlx-sqlite/src/connection/worker.rs index ec8b38f0f6..a27018bf07 100644 --- a/sqlx-sqlite/src/connection/worker.rs +++ b/sqlx-sqlite/src/connection/worker.rs @@ -105,6 +105,7 @@ impl ConnectionWorker { thread::Builder::new() .name(params.thread_name.clone()) + .stack_size(params.thread_stack_size) .spawn(move || { let (command_tx, command_rx) = flume::bounded(params.command_channel_size); diff --git a/sqlx-sqlite/src/options/mod.rs b/sqlx-sqlite/src/options/mod.rs index 5f22edd913..27ee8162a3 100644 --- a/sqlx-sqlite/src/options/mod.rs +++ b/sqlx-sqlite/src/options/mod.rs @@ -70,6 +70,7 @@ pub struct SqliteConnectOptions { pub(crate) log_settings: LogSettings, pub(crate) immutable: bool, pub(crate) vfs: Option>, + pub(crate) thread_stack_size: usize, pub(crate) pragmas: IndexMap, Option>>, /// Extensions are specified as a pair of \, the majority @@ -191,6 +192,8 @@ impl SqliteConnectOptions { // Soft limit on the number of rows that `ANALYZE` touches per index. pragmas.insert("analysis_limit".into(), None); + let default_thread_stack_size = 512 * 1024; // 512KB + Self { filename: Cow::Borrowed(Path::new(":memory:")), in_memory: false, @@ -202,6 +205,7 @@ impl SqliteConnectOptions { log_settings: Default::default(), immutable: false, vfs: None, + thread_stack_size: default_thread_stack_size, pragmas, extensions: Default::default(), collations: Default::default(), @@ -230,6 +234,19 @@ impl SqliteConnectOptions { &self.filename } + /// Set the thread stack size in bytes. + /// + /// The default thread stack size is 512KB. + pub fn thread_stack_size(mut self, size: usize) -> Self { + self.thread_stack_size = size; + self + } + + /// Get the current thread stack size in bytes. + pub fn get_thread_stack_size(&self) -> usize { + self.thread_stack_size + } + /// Set the enforcement of [foreign key constraints](https://www.sqlite.org/pragma.html#pragma_foreign_keys). /// /// SQLx chooses to enable this by default so that foreign keys function as expected,