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

Prisma can't connect with an IPv6 host (on e.g. Fly.io) #18079

Closed
Fenntasy opened this issue Feb 24, 2023 · 12 comments · Fixed by prisma/prisma-engines#4051
Closed

Prisma can't connect with an IPv6 host (on e.g. Fly.io) #18079

Fenntasy opened this issue Feb 24, 2023 · 12 comments · Fixed by prisma/prisma-engines#4051
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. team/schema Issue for team Schema. topic: database-provider/fly.io
Milestone

Comments

@Fenntasy
Copy link

Bug description

In a DATABASE_URL, if the host is an IPv6, Prisma will throw an error, for instance, using this connection string

postgresql://postgres:postgres@[::1]:5432/db

will result in this error

Can't reach database server at `[::1]`:`5433`

I know that locally I could always use localhost or 127.0.0.1 but the bug is more of a problem if you're using a service like Fly that has started populating DATABASE_URL with IPv6 addresses. It just doesn't work out of the box.

psql and the pg node package don't have a problem with them so it's a problem with Prisma.

How to reproduce

Any local PG connection string looking like

postgresql://postgres:postgres@[::1]:5432/db

will create the error

Expected behavior

It should be able to connect.

Prisma information

The schema or queries are irrelevant here since it just doesn't connect.

Environment & setup

  • OS: at least macOS and linux
  • Database: PostgreSQL
  • Node.js version: v18.12.1 (but it doesn't seem linked to that)

Prisma Version

prisma                  : 4.10.1
@prisma/client          : 4.10.1
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine aead147aa326ccb985dcfed5b065b4fdabd44b19 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli aead147aa326ccb985dcfed5b065b4fdabd44b19 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.10.1-1.80b351cc7c06d352abe81be19b8a89e9c6b7c110
Default Engines Hash    : aead147aa326ccb985dcfed5b065b4fdabd44b19
Studio                  : 0.481.0
Preview Features        : tracing
@Fenntasy Fenntasy added the kind/bug A reported bug. label Feb 24, 2023
@cinder-star
Copy link

I would like to investigate on this issue

@cinder-star
Copy link

After going through the code, I found that the $connect() function uses prisma engine. The implementation is in https://github.com/prisma/prisma-engines

@DAlperin
Copy link

Hello from fly.io! As @Fenntasy noted, this bug has an unfortunate effect on prisma apps running on our platform. We'd love to see this fixed. Let me know if any additional information would be useful, or any other way we can help.

@maticzav
Copy link

maticzav commented Mar 1, 2023

@janpio is there any workaround for this that we could use?

@cinder-star
Copy link

@maticzav if you are facing this issue on fly.io, you can attach an ipv4 address to your database and use that. Read here

@maticzav
Copy link

maticzav commented Mar 1, 2023

@cinder-star sweet, thanks!

And how can I find user, password and dbname of a running database?

@cinder-star
Copy link

The dbname, user and password are the same as the connection string with the ipv6 one. You just need to replace the hostname with the ipv4 host. @maticzav

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/schema Issue for team Schema. team/client Issue for team Client. labels Mar 1, 2023
@maticzav
Copy link

maticzav commented Mar 1, 2023

@cinder-star I tried setting up the IPv4 url and manually changing the postgresql url, but that didn't play well with the Prisma Migrate. I did manage to get it working though.

  1. I checked the credentials, which I also found out are only displayed once when you create the PG instance (so you can't use the "automatically" created instance),
  2. I manually recreated the PG instance, connected to it from TablePlus and created a database (e.g. dbname).
  3. I replaced the IPv6 address with myapp.internal (e.g. postgresql://postgres:password@myapp.internal:5432/dbname).

Some useful links and code chunks that helped me figure out

[build]
  dockerfile = "server/Dockerfile"

[deploy]
  release_command = "pnpm migrate:db"
{
  "scripts": {
    "migrate:db": "prisma migrate deploy --schema server/prisma/schema.prisma"
  }
}

Thanks again for helping me again 🙏 !

@cinder-star
Copy link

@maticzav i think you need to add sslmode to the url as well.
postgresql://postgres:password@myapp.internal:5432/dbname?sslmode=disabled
Something like that

@Fenntasy
Copy link
Author

Fenntasy commented Mar 2, 2023

@maticzav i think you need to add sslmode to the url as well.
postgresql://postgres:password@myapp.internal:5432/dbname?sslmode=disabled
Something like that

It's not needed for the .internal URL.

But in any case, this issue shouldn't be about how to fix the problem with Fly when the problem lies with Prisma.

tgautier added a commit to fewlinesco/fly-io-review-apps that referenced this issue Mar 6, 2023
This PR bumps the GitHub Action to v3.0 with the following changes:
- we only create the PostgreSQL Cluster if it doesn't already exist yet
(given specified in the configuration)
- create PostgreSQL cluster with an initial size of 2 so that the write
main instance and the first read replica are in the same region,
additional read replicas can still be spawned in additional regions with
`postgres_cluster_regions` configuration
- replace Fly's Database URL ending with `.flycast` to `.internal` as a
fix for [Prisma Issue](prisma/prisma#18079)
- pass secrets as `--env` option to the `flyctl deploy` command instead
of using `flyctl secrets` to avoid first deployment having no secrets

Fixes TRB-494
@VyrekXD
Copy link

VyrekXD commented May 26, 2023

Is there any fix to this problem?

@janpio janpio changed the title Prisma can't connect with an IPv6 host Prisma can't connect with an IPv6 host on Fly.io Jun 6, 2023
@alula
Copy link

alula commented Jun 20, 2023

This affects everything that uses IPv6 addresses in URLs directly, not just fly.io, old title was fine

@janpio janpio changed the title Prisma can't connect with an IPv6 host on Fly.io Prisma can't connect with an IPv6 host (on e.g. Fly.io) Jun 20, 2023
@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 24, 2023
aqrln added a commit to prisma/prisma-engines that referenced this issue Jul 24, 2023
Add an integration test for connecting to SQL databases with an IPv6
address in a connection string.

This serves as a regression test for the fix for PostgreSQL and MySQL in
1548dc1, as well as confirms that this
already works on MS SQL.

Ref: #4051
Ref: prisma/prisma#18079
aqrln added a commit to prisma/prisma-engines that referenced this issue Jul 25, 2023
Add an integration test for connecting to SQL databases with an IPv6
address in a connection string.

This serves as a regression test for the fix for PostgreSQL and MySQL in
1548dc1, as well as confirms that this
already works on MS SQL.

Ref: #4051
Ref: prisma/prisma#18079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. team/schema Issue for team Schema. topic: database-provider/fly.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants