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

Electric fails to connect to the database if another instance of Electric is already running #971

Open
alco opened this issue Feb 19, 2024 · 1 comment
Labels
bug Something isn't working Restartability

Comments

@alco
Copy link
Member

alco commented Feb 19, 2024

The error looks like this in the log output:

2024-01-18T11:12:44.580068439Z ▓ ┌────────────────────┐
2024-01-18T11:12:44.580106777Z ▓ │  CONNECTION ERROR  │
2024-01-18T11:12:44.580113567Z ▓ ┕━━━━━━━━━━━━━━━━━━━━┙
2024-01-18T11:12:44.580118544Z ▓ 
2024-01-18T11:12:44.580125387Z ▓ Failed to establish replication connection to Postgres:
2024-01-18T11:12:44.580133704Z ▓   replication slot "electric_replication_out_defaultdb" is active for PID 38381
2024-01-18T11:12:44.580140172Z ▓ 
2024-01-18T11:12:44.580144738Z ▓ Another instance of Electric appears to be connected to this database.
2024-01-18T11:12:44.580318925Z 11:12:44.579 pid=<0.2795.0> origin=postgres_1 [error] PostgresConnectorSup failed to start child :postgres_producer with reason: {:bad_return_value, {:error, {:error, :error, "55006", :object_in_use, "replication slot \"electric_replication_out_defaultdb\" is active for PID 38381", [file: "slot.c", line: "516", routine: "ReplicationSlotAcquire", severity: "ERROR"]}}}.
2024-01-18T11:12:44.580413865Z 11:12:44.579 pid=<0.2795.0> origin=postgres_1 [info] schedule retry: 2000

This can happen on some hosting platforms where a configuration change in an already deployed instance of Electric will cause a new instance to be started to use the update config. The new instance will not be able to establish a replication connection to the database until the old instance shuts down.

The reason there can only be one Electric instance connected to a database at any given time is that Electric uses a replication connection to listen for changes originating in Postgres. Supporting multiple instances running simultaneously requires careful design and development to ensure that consistency is preserved and that the load is split evenly between all instances.

Until we address the underlying limitation, we suggest using one of these workarounds:

  • stop the running instance of Electric before starting a new one
  • use a TCP health check (as opposed to an HTTP health check for /api/status) when deploying Electric to a hosting platform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Restartability
Projects
None yet
Development

No branches or pull requests

1 participant