Skip to content

Invalid memory reference error when running test in project that sets session_preload_libraries in _bootstart.sql #816

Closed
@osawyerr

Description

@osawyerr

This happens on MacOS on M1 processor
PGX - 0.5.6
_bootstap.sql file is based on a similar file from ZomboDB project.

Restarting my machine fixes the issue and test is successful. There was a similar error that was reported sometime back - #357. I'm not sure if its a similar issue here.

To recreate:

  • Create new project
    cargo pgx new foo
  • Run test to verify everything works ok
    cargo pgx test
  • Add the following in _bootstrap.sql file in sql folder
    DECLARE
        session_preload_libraries text;
    BEGIN
        session_preload_libraries = COALESCE (current_setting('session_preload_libraries'), '');
        IF (session_preload_libraries NOT LIKE '%foo.so%') THEN
            IF (session_preload_libraries = '') THEN
                session_preload_libraries = 'foo.so';
            ELSE
                session_preload_libraries = format('foo.so,%s', session_preload_libraries);
            END IF;

            EXECUTE format('ALTER DATABASE %I SET session_preload_libraries TO ''%s''', current_database(), session_preload_libraries);
        END IF;

    END;
$$;
  • Add line to load _bootstrap.sql in lib.rs
    extension_sql_file!("../sql/_bootstrap.sql", bootstrap);
  • Rerun test
    cargo pgx test

Error

error: test failed, to rerun pass '--lib'

Caused by:
  process didn't exit successfully: `....` (signal: 11, SIGSEGV: invalid memory reference)

Not sure how useful this is but I was able to capture a stack trace in my IDE. Message was "Postgres failed to start"

[foo-9a14b65cd5846f08] rust_panic panicking.rs:746
[foo-9a14b65cd5846f08] rust_panic_with_hook panicking.rs:716
[foo-9a14b65cd5846f08] {closure#0} panicking.rs:588
[foo-9a14b65cd5846f08] __rust_end_short_backtrace<std::panicking::begin_panic_handler::{closure_env#0}, !> backtrace.rs:138
[foo-9a14b65cd5846f08] begin_panic_handler panicking.rs:584
[foo-9a14b65cd5846f08] panic_fmt panicking.rs:142
[foo-9a14b65cd5846f08] unwrap_failed result.rs:1814
[foo-9a14b65cd5846f08] expect<(u32, alloc::string::String), std::sync::mpsc::RecvError> result.rs:1064
[foo-9a14b65cd5846f08] monitor_pg framework.rs:558
[foo-9a14b65cd5846f08] start_pg framework.rs:478
[foo-9a14b65cd5846f08] initialize_test_framework framework.rs:230
[foo-9a14b65cd5846f08] run_test framework.rs:124
[foo-9a14b65cd5846f08] pg_test_create_index mod.rs:155
[foo-9a14b65cd5846f08] {closure#0} mod.rs:155
[foo-9a14b65cd5846f08] call_once<foo::schema::tests::pg_test_create_index::{closure_env#0}, ()> function.rs:248
[Inlined] [foo-9a14b65cd5846f08] core::ops::function::FnOnce::call_once function.rs:248
[foo-9a14b65cd5846f08] __rust_begin_short_backtrace<fn()> lib.rs:572
[Inlined] [foo-9a14b65cd5846f08] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once boxed.rs:1935
[Inlined] [foo-9a14b65cd5846f08] _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once unwind_safe.rs:271
[Inlined] [foo-9a14b65cd5846f08] std::panicking::try::do_call panicking.rs:492
[Inlined] [foo-9a14b65cd5846f08] std::panicking::try panicking.rs:456
[Inlined] [foo-9a14b65cd5846f08] std::panic::catch_unwind panic.rs:137
[Inlined] [foo-9a14b65cd5846f08] test::run_test_in_process lib.rs:595
[foo-9a14b65cd5846f08] {closure#0} lib.rs:489
[Inlined] [foo-9a14b65cd5846f08] test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$ lib.rs:516
[foo-9a14b65cd5846f08] __rust_begin_short_backtrace<test::run_test::run_test_inner::{closure_env#1}, ()> backtrace.rs:122
[Inlined] [foo-9a14b65cd5846f08] std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$ mod.rs:505
[Inlined] [foo-9a14b65cd5846f08] _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once unwind_safe.rs:271
[Inlined] [foo-9a14b65cd5846f08] std::panicking::try::do_call panicking.rs:492
[Inlined] [foo-9a14b65cd5846f08] std::panicking::try panicking.rs:456
[Inlined] [foo-9a14b65cd5846f08] std::panic::catch_unwind panic.rs:137
[Inlined] [foo-9a14b65cd5846f08] std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$ mod.rs:504
[foo-9a14b65cd5846f08] call_once<std::thread::{impl#0}::spawn_unchecked_::{closure_env#1}<test::run_test::run_test_inner::{closure_env#1}, ()>, ()> function.rs:248
[Inlined] [foo-9a14b65cd5846f08] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once boxed.rs:1935
[Inlined] [foo-9a14b65cd5846f08] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once boxed.rs:1935
[foo-9a14b65cd5846f08] thread_start thread.rs:108
[libsystem_pthread.dylib] _pthread_start 0x00000001aad8c26c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions