question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in google cloud run connecting with cloud SQL

See original GitHub issue

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"

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
dkozmacommented, Feb 5, 2020

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

postgres://USER:PASSWORD@localhost/DBNAME?host=/cloudsql/CLOUD_SQL_INSTANCE_CONNECTION_NAME
2reactions
diegocoutocommented, Jun 4, 2020

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? ☺️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud SQL error messages
Error messages in Cloud SQL come from many sources and appear in many places. ... Connect to the database (for example, using Cloud...
Read more >
cloud run - error while connecting to cloud sql - Stack Overflow
I am using gcloud run to deploy the app directly from source code. So image is being build and deployed by google cloud...
Read more >
How to Connect to GCP Cloud SQL Instances in Cloud Run ...
Connect to Cloud SQL instances with private IPs in minutes ... If you use the Google Cloud Platform (GCP), it's common to access...
Read more >
Cloud Run connection to Cloud SQL times out occassionally
Please see https://cloud.google.com/sql/docs/mysql/connect-run for ... A few minutes before and after these errors, requests are being ...
Read more >
Cloud Run occassionally throws "connection timed out" from ...
Edit #2: As @JohnHanley and @jjanes pointed out in the comments, from the error it seems like Cloud Run is trying to connect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found