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

Unstable connection to postgres via proxy #495

Open
esulzickis opened this issue Dec 11, 2024 · 3 comments
Open

Unstable connection to postgres via proxy #495

esulzickis opened this issue Dec 11, 2024 · 3 comments

Comments

@esulzickis
Copy link

esulzickis commented Dec 11, 2024

Terraform Version

opentofu 1.8.2

Affected Resource(s)

  • postgresql_role
  • postgresql_grant_role
  • postgresql_database

Terraform Configuration Files

provider "postgresql" {
  host      = var.db_endpoint
  port      = 5432
  database  = "postgres"
  username  = local.db_creds.username
  password  = local.db_creds.password
  sslmode   = "require"
  superuser = false
  #
  max_connections = 0
  connect_timeout = 360
}

Debug Output

https://gist.github.com/esulzickis/25d5e40cf893e4957d1ba0e10d123aef

Expected Behavior

Connecting to postgresql_role resource through tailscale proxy should not show an error

Actual Behavior

Sometimes when connecting through proxy connection works and sometimes not. The behavior is unstable

Steps to Reproduce

  1. export ALL_PROXY="socks5h://localhost:1055"
  2. tofu plan
@Gowiem
Copy link

Gowiem commented Dec 30, 2024

@esulzickis my team and I are running into this same issue. It's intermittent and frustrating. Have you figured any workaround or stopgap that helps with the intermittent issues? Do you know if the issue is with this provider or is that just a guess?

@esulzickis
Copy link
Author

In our case we use tailscale as a VPN solution. We changed connection type from relay to direct (https://tailscale.com/kb/1257/connection-types) and it helped a little bit. However 2 out of 24 plans still failed. Another thing I have noticed is that when comparing mysql (https://registry.terraform.io/providers/petoju/mysql/latest) and postgresql terraform providers TF logs I saw that mysql provider one has some retry logic each time when it fails to connect to mysql and postgresql is missing that. I was thinking that implementing retry connection logic in postgresql terraform provider could also help

@Gowiem
Copy link

Gowiem commented Jan 10, 2025

@esulzickis thanks for the follow up! We're going to try to build "Favor Direct Connections" support into our terraform module and see if that helps... 🤞

I do like your callout that this provider lacks connection retry logic. I wonder if we should create a separate ticket to see if that is possible? Or maybe that is what this ticket should morph into?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants