Comments (25)
I've assigned the Dart issue (dart-lang/sdk#47899) to myself but I probably won't have time to take a look at this until next week.
from functions-framework-dart.
There are more details here: dart-lang/sdk#47899
But my current hypothesis is that the gVisor containerization used in the gen1 Cloud Run execution environment implements a syscall differently than Dart expects.
You can work around that by using the gen2 execution environment, see selecting an execution environment.
I can no longer reproduce the issue if I change this repo: https://github.com/davidmartos96/cloud-run-dart-pg-issue
with:
diff --git a/Makefile b/Makefile --add-cloudsql-instances=$(CLOUD_SQL_CONNECTION_NAME) \ --set-env-vars=DB_USER=$(DB_USER),DB_PASS=$(DB_PASS),DB_NAME=$(DB_NAME),CLOUD_SQL_CONNECTION_NAME=$(CLOUD_SQL_CONNECTION_NAME) \ + --execution-environment=gen2My next step is to try to reproduce this using gVisor directly to see if this is a bug in Dart or gVisor.
Thank you it helped only this (gen2)
from functions-framework-dart.
CC @mit-mit – I'm guessing this is not specific to this framework, and likely something deeper in pkg:shelf or dart:io
Will dig in here!
from functions-framework-dart.
There are more details here: dart-lang/sdk#47899
But my current hypothesis is that the gVisor containerization used in the gen1 Cloud Run execution environment implements a syscall differently than Dart expects.
You can work around that by using the gen2 execution environment, see selecting an execution environment.
I can no longer reproduce the issue if I change this repo:
https://github.com/davidmartos96/cloud-run-dart-pg-issue
with:
diff --git a/Makefile b/Makefile
--add-cloudsql-instances=$(CLOUD_SQL_CONNECTION_NAME) \
--set-env-vars=DB_USER=$(DB_USER),DB_PASS=$(DB_PASS),DB_NAME=$(DB_NAME),CLOUD_SQL_CONNECTION_NAME=$(CLOUD_SQL_CONNECTION_NAME) \
+ --execution-environment=gen2
My next step is to try to reproduce this using gVisor directly to see if this is a bug in Dart or gVisor.
from functions-framework-dart.
Could you get a repro of this working with docker-compose? (With Dart + postgres?)
Would make debugging a LOT easier!
from functions-framework-dart.
Could you get a repro of this working with docker-compose? (With Dart + postgres?)
Would make debugging a LOT easier!
You mean working with a regular Postgres database on Docker with Unix sockets? I can try to do that.
from functions-framework-dart.
Yeah – and if you included a docker compose
setup yaml in the repo, it makes reproducing on our side a LOT easier!
from functions-framework-dart.
@kevmoo I've updated the sample with a docker compose ready to run the app with a local Postgres. As you'll see, the socket connection works correctly locally.
from functions-framework-dart.
I'd be surprised if unix socket works on run at all. You're saying it DOES work?
Have you tried TCP? Does that work?
from functions-framework-dart.
Are you using Cloud SQL?
Have you looked at https://cloud.google.com/sql/docs/postgres/connect-run#connecting_to ?
from functions-framework-dart.
@kevmoo Yes, Unix sockets work correctly, but only locally 😅
TCP works just fine both locally and on Cloud Run. The problem is that in the Cloud Run environment the IP is unknown, so we cannot add an authorized network for it in Cloud SQL. We would need to add 0.0.0.0/0 to use TCP from Cloud Run.
Yes, we looked at the provided docs, and that's how we got to connect it. The issue is just in the second connection. Our Cloud SQL uses public IP, so the docs state to use the Unix socket connection mounted in the /cloudsql path.
from functions-framework-dart.
We've also tried deploying the node.js demo, which connects to the same socket path, and it works. It seems to be something related to Dart.
from functions-framework-dart.
Hey @kevmoo, any updates on this? Like some other issue I could track?
from functions-framework-dart.
I think I might be experiencing the same problem. When I deploy this app to Cloud Run (via terraform) and then make a HTTP request to it, in the majority of times the request hangs on indefinitely until it returns 504
, and sometimes it returns OK. I even opened an issue for that because it is puzzling.
I'm using the postgres_pool package to create the connection.
from functions-framework-dart.
Is there currently an owner for this issue? If not, I'll assign it (and the related dart-lang/sdk#47899) to myself.
from functions-framework-dart.
@brianquinlan Please! Happy to help here. I don't have the tech chops to help figure out what's happening.
Other folks here, I have a question: have you ever tried to containerize your app locally and then connect to Cloud SQL?
Trying to figure out if this is a Docker/container thing or a Cloud Run thing...
from functions-framework-dart.
@kevmoo When I encountered with this issue I tried connecting via Unix socket through the Cloud SQL Proxy (https://cloud.google.com/sql/docs/postgres/sql-proxy) and the socket connection through Dart was working fine, but I wasn't able to containerize the proxy.
From the tests I did my guess is that it could be something in Dart io or Cloud Run, and not a Postgres library issue.
from functions-framework-dart.
@kevmoo I created a branch to test this https://github.com/marcusmonteirodesouza/dart-shelf-realworld-example-app/tree/test/cloudsql-proxy-containerized
I made some requests to my local endpoint and they all returned OK
. I checked and the data was saved in my CloudSQL database. So a local containerized app connected to CloudSQL Proxy seems to work.
from functions-framework-dart.
I'm pretty sure that this is a gVisor issue.
I've filed a bug with the gVisor team: google/gvisor#7331
@kevmoo The workaround is to use the gen2 execution environment, see selecting an execution environment.
Do we want to update our documentation (e.g. https://github.com/GoogleCloudPlatform/functions-framework-dart/blob/main/docs/quickstarts/03-quickstart-cloudrun.md) to suggest using the gen2 execution environment?
from functions-framework-dart.
@brianquinlan – not a bad idea! Let's leave this issue open to track that...
from functions-framework-dart.
@kevmoo I can change the Cloud Run quickstart. Do you know of any other documents that need to be updated?
from functions-framework-dart.
@kevmoo Also, are you an admin for this repo? If so, could you give me permission to modify issues?
from functions-framework-dart.
The docs for Cloud Run now say that docker is used as the execution environment:
https://cloud.google.com/run/docs/about-execution-environments
So is this still an issue?
from functions-framework-dart.
I don't think so. We found the root cause.
from functions-framework-dart.
If anyone hits this issue again, please reopen this bug.
from functions-framework-dart.
Related Issues (20)
- Error Reporting in Cloud Run HOT 4
- sample project created via dartfn should use official docker images HOT 3
- Docker files created by dartfn doesn't copy runtime files, causing launch to fail HOT 3
- dartfn-generated project fails tests locally HOT 9
- dartfn: need to have a dependency to pkg:lints!
- dartfn: gitignore files should link to https://dart.dev/guides/libraries/private-files
- Pricing and/or other considerations regarding using Cloud Run for simulating Cloud Functions?
- Multiple functions in the same package HOT 3
- Docker images failing when deployed to cloud run when using apple silicon HOT 1
- Private SSH packages HOT 1
- Generated project (from dartfn) logs CloudEvent awkwardly HOT 3
- Allow Configuring "X-Powered-By" of underlying shelf server HOT 1
- Support for Protobufs in CloudEvents HOT 6
- Provide access to an instance's region from metadata HOT 1
- gcp: logging does not support jsonPayload HOT 1
- DRY up finishServerTest code and similar HOT 2
- Multiple funcitons in one project HOT 3
- BuildRunner seems to break the code HOT 7
- "Not compatible with a supported function shape" when using RequestContext parameter HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functions-framework-dart.