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

RuntimeError: unreachable when using loadDataDir #462

Closed
joehan opened this issue Dec 9, 2024 · 9 comments
Closed

RuntimeError: unreachable when using loadDataDir #462

joehan opened this issue Dec 9, 2024 · 9 comments
Assignees

Comments

@joehan
Copy link

joehan commented Dec 9, 2024

Hi, I'm a maintainer of firebase-tools, which has a dependency on pglite. We recently added a import/export feature, where we export Postgres data using dumpDataDir() and then import it on future runs using loadDataDir when we next start up the PGlite database. Some users of this feature have reported the following error when importing data (firebase/firebase-tools#8044):

    at wasm://wasm/0222924a:wasm-function[5668]:0x42d017
    at wasm://wasm/0222924a:wasm-function[4558]:0x3a93a4
    at wasm://wasm/0222924a:wasm-function[2877]:0x2505b8
    at Module._pg_initdb (/Users/joehanley/Workspace/firebase-tools/node_modules/@electric-sql/pglite/dist/index.cjs:12:118235)
    at eE.ua (/Users/joehanley/Workspace/firebase-tools/node_modules/@electric-sql/pglite/dist/index.cjs:12:2428733)
    at async eE.create (/Users/joehanley/Workspace/firebase-tools/node_modules/@electric-sql/pglite/dist/index.cjs:12:2423415)

This only occurs sometimes, and I'm having trouble debugging due to the opaque WASM error.

Reproduction instructions:

Using the following example postgres dump:
postgres.tar.gz

const rf = fs.readFileSync("postgres.tar.gz");
const file = new File([rf], "postgres.tar.gz");
const pgliteArgs: PGliteOptions = {
  username: "blah"
  database: "postgres",
  debug: 0,
  extensions: {
    vector,
    uuidOssp,
  },
  loadDataDir: "postgres.tar.gz",
};

const db = await PGlite.create(pgliteArgs);

In case its relevant, postgres.tar.gz was originally generated via the following code:

    const dump = await db.dumpDataDir();
    const arrayBuff = await dump.arrayBuffer();
    fs.writeFileSync(exportPath, new Uint8Array(arrayBuff));

Any pointers on how to understand this error or ideas on what is wrong with the dumped TAR?

@samwillis
Copy link
Collaborator

Hey @joehan, thanks for the report. We'll take a look at it and get back to you asap.

@copiltembel copiltembel self-assigned this Dec 10, 2024
@yacineb
Copy link
Contributor

yacineb commented Dec 10, 2024

@joehan can you please tell us which pglite version are you using ? thks

@copiltembel
Copy link
Collaborator

@joehan This seems related to loading a dump with a username and database specified. We're looking into it.

@joehan
Copy link
Author

joehan commented Dec 10, 2024

@joehan can you please tell us which pglite version are you using ? thks

Sorry, meant to include this in the orignal message. We are currently using 0.2.0 - however, I also tried updating to 0.2.15 and the issue was still occurring.

@joehan
Copy link
Author

joehan commented Dec 11, 2024

@joehan This seems related to loading a dump with a username and database specified. We're looking into it.

Do you know specifically what triggers it? If so, we might be able to avoid that situation in the firebase-tools codebase as a immediate workaround.

@copiltembel
Copy link
Collaborator

@joehan Could you please try by not specifying the username and database?

@copiltembel
Copy link
Collaborator

@joehan Did the above workaround solve it for you?

@joehan
Copy link
Author

joehan commented Jan 13, 2025

Sorry for the radio silence - yes, that workaround was successful! Thank you for the help 🙏

@jamesarosen
Copy link

It would be lovely to have a more descriptive error message. Even better, PGliteOptions could be something like

type PGliteOptions =
  | { loadDataDir: string; username: never; database: never; }
  | { loadDataDir: never; username?: string; database?: string; }
  ...

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

No branches or pull requests

5 participants