prisma: Error in google cloud run connecting with cloud SQL

The error message i get when running in docker with cloud run:

"\nInvalid prisma.() invocation in\n/usr/src/app/src/federations/b2bike/entities/service-pass/resolvers.js:6:76\n\n\n\nReason: Error occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timeout\n\nstack backtrace:\n 0: failure::backtrace::internal::InternalBacktrace::new\n 1: failure::backtrace::Backtrace::new\n 2: sql_query_connector::error::SqlError::into_connector_error\n 3: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 4: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 5: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 6: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 7: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 8: std::future::poll_with_tls_context\n 9: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 10: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 11: std::panicking::try::do_call\n 12: __rust_maybe_catch_panic\n at src/libpanic_unwind/lib.rs:78\n 13: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 14: <std::future::GenFuture<T> as core::future::future::Future>::poll\n 15: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_catch\n 16: <hyper::server::conn::spawn_all::NewSvcTask<I,N,S,E,W> as core::future::future::Future>::poll\n 17: tokio::task::core::Core<T>::poll\n 18: std::panicking::try::do_call\n 19: __rust_maybe_catch_panic\n at src/libpanic_unwind/lib.rs:78\n 20: tokio::task::harness::Harness<T,S>::poll\n 21: tokio::runtime::thread_pool::worker::GenerationGuard::run_task\n 22: tokio::runtime::thread_pool::worker::GenerationGuard::run\n 23: std::thread::local::LocalKey<T>::with\n 24: tokio::runtime::thread_pool::worker::Worker::run\n 25: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once\n 26: std::panicking::try::do_call\n 27: __rust_maybe_catch_panic\n at src/libpanic_unwind/lib.rs:78\n 28: tokio::task::harness::Harness<T,S>::poll\n 29: tokio::runtime::blocking::pool::Inner::run\n 30: tokio::runtime::context::enter\n 31: std::sys_common::backtrace::__rust_begin_short_backtrace\n 32: std::panicking::try::do_call\n 33: __rust_maybe_catch_panic\n at src/libpanic_unwind/lib.rs:78\n 34: core::ops::function::FnOnce::call_once{{vtable.shim}}\n 35: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once\n at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/liballoc/boxed.rs:942\n 36: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once\n at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/liballoc/boxed.rs:942\n std::sys_common::thread::start_thread\n at src/libstd/sys_common/thread.rs:13\n std::sys::unix::thread::Thread::new::thread_start\n at src/libstd/sys/unix/thread.rs:79\n 37: start_thread\n 38: __clone\n) })\n"

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

A Cloud Run-compatible socketpath can be provided to Prisma, for instance:

postgres://USER:PASSWORD@localhost/DBNAME?host=/cloudsql/CLOUD_SQL_INSTANCE_CONNECTION_NAME

Hi everyone,

Updated message (June 04, 2020):

I was able to solve this issue using ?socket= instead of ?host=. This was suggested in this thread before but, as the documentation was updated after it’s been discussed here, I was under the impression that this had been updated as well.

Original Message

Were any of you able to set up a socket connection when using MySQL as the provider? I’ve been trying to do so but I keep seeing the error:

"extensions": {
  "code": "INTERNAL_SERVER_ERROR",
  "exception": {
    "code": "P1001",
    "meta": {
      "database_host": "localhost",
      "database_port": 3306
    },
    "stacktrace": [
      "Error: ",
      "Invalid `prisma.user.findOne()` invocation in",
      "/usr/src/app/build/controllers/UserController.js:113:68",
      "",
      "",
      "  Can't reach database server at `localhost`:`3306`",
      "",
      "Please make sure your database server is running at `127.0.0.1`:`3306`.",
      "    at PrismaClientFetcher.request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:1:148505)",

In order to limit potential issues, I’m hardcoding the data source URL while testing this as such:

datasource db {
  provider = "mysql"
  url      = "mysql://user:psswd@localhost/db?host=/cloudsql/project:region:db"
}

To make sure the issue was not related to some missing permissions between Cloud Run and Cloud SQL, I’ve created a Knex client trying to connect to the same socket and it does connect successfully.

I’m not sure whether this could be an indicator or not but it’s weird that the error message never mentions the socket, only the IP:PORT, making it look like it’s always trying a TCP connection only.

Any thoughts? ☺️

Just wanted to verify that (PostgreSQL, at least) is working with preview-021 using the following connection string:

postgres://USER:PASSWORD@localhost/DBNAME?host=/cloudsql/CLOUD_SQL_INSTANCE_CONNECTION_NAME

According to @pimeys ’ post, the MySQL version should look something like:

mysql://USER:PASSWORD@localhost/DBNAME?socket=(/cloudsql/CLOUD_SQL_INSTANCE_CONNECTION_NAME)

@diegocouto Have you tried the MySQL-specific connection string mentioned here (note socket and the parenthesis)? https://github.com/prisma/prisma/issues/1508#issuecomment-587728466

Edit: Didn’t see your edit. Thanks for opening that documentation PR.

@Sytten thanks, I enabled the Cloud SQL Admin API and now it works perfectly!

Sorry for the delay, I need to verify it’s working with preview-021. Also I haven’t tested this with MySQL, so the connection string might be different. Will update once I’ve verified the latest release.