electric-sql / electric

Sync little subsets of your Postgres data into local apps and services.
https://electric-sql.com
Apache License 2.0
6.5k stars 156 forks source link

Cloud Service shuts down when Proxy Tunnel is enabled. #1428

Closed fnacarellidev closed 4 months ago

fnacarellidev commented 4 months ago

I'm trying to deploy and electric-sql service for the first time on the Google Cloud Platform, as decribed on https://electric-sql.com/docs/api/cli#proxy-tunnel I tried enabling the proxy tunnel since the GCP services indeed only support HTTP connections, at first I stumbled on this problem and kept receiving the following error message:

▓ ┌────────────────────────────────────┐ ▓ │ MODULE ERROR: Electric.Replication.PostgresConnector │ ▓ ┕━━━━━━━━━━━━━━━━━━━━━━━━━┙ ▓ Failed to start child Electric.Satellite.ClientReconnectionInfo: ▓ {%DBConnection.ConnectionError{message: "connection not available and request was dropped from queue after 2000ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:\n\n 1. Ensuring your database is available and that you can connect to it\n 2. Tracking down slow queries and making sure they are running fast enough\n 3. Increasing the pool_size (although this increases resource consumption)\n 4. Allowing requests to wait longer by increasing :queue_target and :queue_interval\n\nSee DBConnection.start_link/2 for more information\n", severity: :error, reason: :queue_timeout}, [{DBConnection, :run, 3, [file: ~c"lib/db_connection.ex", line: 960, error_info: %{module: Exception}]}, {Electric.Satellite.ClientReconnectionInfo, :init, 1, [file: ~c"lib/electric/satellite/client_reconnection_info.ex", line: 1028]}, {:gen_server, :init_it, 2, [file: ~c"gen_server.erl", line: 2057]}, {:gen_server, :init_it, 6, [file: ~c"gen_server.erl", line: 2012]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 329]}]}

After a while trying to find the solution, I remembered I had set wal_level to logical, and I was currently using "ELECTRIC_WRITE_TO_PG_MODE"=direct_writes so I resetted the database and kept wal_level as replica, things started working, I was no longer receiving that error but it came back, and I can't fix no matter what I try, I already resetted the service countless times, I already tried resetting the DB instance too (POSTGRES 14), I'd really try to get electric running on a production environment to test it out, hopefully I can get some help here, if there's any info you guys need please let me know.

That's the Config Connector configuration i'm currently using:

apiVersion: run.cnrm.cloud.google.com/v1beta1
kind: RunService
metadata:
  name: books-electric-sql
spec:
  ingress: INGRESS_TRAFFIC_ALL
  location: us-central1
  projectRef:
    external: projects/my-project
  template:
    containers:
    - name: electric-sql
      image: electricsql/electric@sha256:d2c6d6930d60926c949e7e0f3f55957e143b48fdc4b7852aa4d7bffb8e86e4da
      ports:
       - containerPort: 5133
      env:
      - name: DATABASE_URL
        value: postgresql://postgres:<pass>@<host>:5432/postgres?sslmode=disable
      - name: DATABASE_REQUIRE_SSL
        value: "false"
      - name: PG_PROXY_PASSWORD
        value: proxy_password
      - name: AUTH_MODE
        value: insecure
      - name: ELECTRIC_WRITE_TO_PG_MODE
        value: direct_writes
      - name: PG_PROXY_PORT
        value: http
---
linear[bot] commented 4 months ago

VAX-2008 Cloud Service shuts down when Proxy Tunnel is enabled.

fnacarellidev commented 4 months ago

For now it's working, i'm using the exact same setup, but with wal_level=logical, probably it will stop working soon, the last time I got it working for half an hour and it suddenly stopped working.

fnacarellidev commented 4 months ago

Added this to the old setup and now it seems to work, will keep the issue open while I make some tests, but I think this might solve the problem.

+      startupProbe:
+        failureThreshold: 3
+        initialDelaySeconds: 10
+        periodSeconds: 30
+        tcpSocket:
+          port: 65432