Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move loading httpfs and setting extension directory to beginning of connection #204

Merged
merged 8 commits into from
Feb 3, 2025

Conversation

rebasedming
Copy link
Contributor

Ticket(s) Closed

  • Closes #

What

Moves loading httpfs and setting the extension directory to the start of the DuckDB connection so that the settings are available to the rest of the connection.

Why

How

Tests

@kysshsy
Copy link
Contributor

kysshsy commented Feb 2, 2025

Happy to see you already submitted a PR to fix this issue. 😁
And I am investigating why the CI didn't pass, my preliminary findings suggest that calling execute within init_globals might be causing the issue. This is because execute triggers the initialization of the connection, which in turn calls init_globals

@kysshsy
Copy link
Contributor

kysshsy commented Feb 2, 2025

And maybe we don't need to INSTALL httpfs manually as Duckdb will load it automatically

@kysshsy
Copy link
Contributor

kysshsy commented Feb 3, 2025

It appears that the deadlock in the connection is indeed caused by the recursive call to init_global within call_once. We can refactor it. like

pub fn set_duckdb_extension_directory(conn: &Connection) -> Result<usize> {
    let data_dir = unsafe {
        CStr::from_ptr(pgrx::pg_sys::DataDir)
            .to_str()
            .map_err(|e| anyhow::anyhow!("Failed to convert DataDir to &str: {}", e))?
    };
    conn.execute(format!("SET extension_directory = '{data_dir}'").as_str(), []).map_err(|err| anyhow!("{err}"))
}

Signed-off-by: Philippe Noël <[email protected]>
@philippemnoel
Copy link
Collaborator

It appears that the deadlock in the connection is indeed caused by the recursive call to init_global within call_once. We can refactor it. like

pub fn set_duckdb_extension_directory(conn: &Connection) -> Result<usize> {
    let data_dir = unsafe {
        CStr::from_ptr(pgrx::pg_sys::DataDir)
            .to_str()
            .map_err(|e| anyhow::anyhow!("Failed to convert DataDir to &str: {}", e))?
    };
    conn.execute(format!("SET extension_directory = '{data_dir}'").as_str(), []).map_err(|err| anyhow!("{err}"))
}

Thank YOU for fixing this!

@philippemnoel philippemnoel merged commit 31985cf into dev Feb 3, 2025
11 checks passed
@philippemnoel philippemnoel deleted the fix/pgdata branch February 3, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants