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

pg-gateway, pglite, and Atlas #12

Open
joehan opened this issue Sep 3, 2024 · 2 comments
Open

pg-gateway, pglite, and Atlas #12

joehan opened this issue Sep 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@joehan
Copy link

joehan commented Sep 3, 2024

Bug report

Describe the bug

I have a basic server set up (similar to https://github.com/supabase-community/pg-gateway?tab=readme-ov-file#pglite), and I'm trying to use Atlas to migrate the schema of my database. However, when I do run:

atlas schema inspect   --url "postgres://:5432/postgres?search_path=public&sslmode=disable"

I get

Error: postgres: querying schemas: pq: unexpected Describe statement response 'Z'

I spent some time under the hood on this, and it seems like pglite/pg-gateway is sending back an extra, unexpected Ready for Query message when replying to Parse or Bind messages. After adding a bunch of logging, this was the problematic message exchange:


Atlas:

Send Parse message

Send Describe message

Send Sync message
______________________________
Backend:

Send ParseComplete message:
1\u0000\u0000\u0000\u0004

Send Ready for Query message: // This one seems unexpected
Z\u0000\u0000\u0000\u0005I"

Send Parameter description message:
"t\u0000\u0000\u0000\n\u0000\u0001\u0000\u0000\u0000\u0013

Send Row description message:
T\u0000\u0000\u0000>O <omitted for length>

Send Ready for query message
Z\u0000\u0000\u0000\u0005I"
_____________________________

Atlas consume consumes ParseComplete.

Atlas tries to consume Parameter Description message, and errors when it instead sees a Ready for Query instead

I'm pretty stumped at this point, and was hoping someone with a better grasp of the wire protocol can explain why this isn't working as expected.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. From the pglite example, start up the server with npm run dev
  2. Download Atlas: curl -sSf https://atlasgo.sh | sh
  3. Run any Atlas command against the server: atlas schema inspect --url "postgres://:5432/postgres?search_path=public&sslmode=disable"

Expected behavior

Atlas successfully queries pglite and plans a migration.

System information

  • OS: Repro'd on macOs and Linux
  • Version of Node.js: 20.11.0
@joehan joehan added the bug Something isn't working label Sep 3, 2024
@gregnr
Copy link
Contributor

gregnr commented Sep 3, 2024

Thanks for reporting @joehan! This sounds like the exact same issue as #4. We identified this as a problem with PGlite during the extended query protocol (tracked here).

The ElectricSQL team is aware of the problem and currently working on a fix. In the meantime the only other solution could be to add custom logic that omits the incorrect ReadyForQuery messages, but only during an extended query flow.

@joehan
Copy link
Author

joehan commented Sep 4, 2024

Thanks so much for the quick reply, glad to see I'm not going crazy 😅 I'll keep an eye on electric-sql/pglite#223 for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants