zed-industries/zed · error

Write queue unexpectedly closed

Error message

Write queue unexpectedly closed

What it means

Invariant expect in sqlez ThreadSafeConnection::write(): the per-URI write queue is missing from the global queue map, though it is inserted at build time — the queue was removed/closed while a write was still being issued.

Source

Thrown at crates/sqlez/src/thread_safe_connection.rs:189

        callback: impl 'static + Send + FnOnce(&Connection) -> T,
    ) -> impl Future<Output = T> {
        // Check and invalidate queue and maybe recreate queue
        let queues = QUEUES.read();
        let write_channel = queues
            .get(&self.uri)
            .expect("Queues are inserted when build is called. This should always succeed");

        // Create a one shot channel for the result of the queued write
        // so we can await on the result
        let (sender, receiver) = oneshot::channel();

        let thread_safe_connection = (*self).clone();
        write_channel(Box::new(move || {
            let connection = thread_safe_connection.deref();
            let result = connection.with_write(|connection| callback(connection));
            sender.send(result).ok();
        }));
        receiver.map(|response| response.expect("Write queue unexpectedly closed"))
    }

    pub(crate) fn create_connection(
        persistent: bool,
        uri: &str,
        connection_initialize_query: Option<&'static str>,
    ) -> Connection {
        let mut connection = if persistent {
            Self::open_file(uri)
        } else {
            Self::open_shared_memory(uri)
        };

        if let Some(initialize_query) = connection_initialize_query {
            let mut last_error = None;
            let initialized = (0..CONNECTION_INITIALIZE_RETRIES).any(|attempt| {
                match connection
                    .exec(initialize_query)

View on GitHub (pinned to f4178619ac)

Solutions

  1. Recreate the background thread and queue on send failure
  2. Investigate why the sqlezWorker thread exited (panic in a write callback)
  3. Return an error to callers instead of panicking
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/sqlez/src/thread_safe_connection.rs:189 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/00f56dc06299994e. Report an issue: GitHub.