validops-east-1 commited on
Commit
8939ab1
·
1 Parent(s): 0d96a43

fix(whatsapp): keep pooler hostname for SNI, dial via hostaddr IPv4

Browse files
Files changed (1) hide show
  1. whatsapp-service/pkg/config/config.go +10 -11
whatsapp-service/pkg/config/config.go CHANGED
@@ -125,11 +125,13 @@ func withConnectTimeout(dsn string, seconds int) string {
125
  return dsn
126
  }
127
 
128
- // forceIPv4DSN rewrites the DSN host to its resolved IPv4 address. Container
129
- // runtimes (HF Spaces, many CI/cloud networks) frequently have no IPv6 route;
130
- // a hostname whose DNS returns only an AAAA record first then fails to connect
131
- // ("network is unreachable"). lib/pq dials whatever family the URL names, so
132
- // pin the address to IPv4 to keep the connection working on IPv6-less hosts.
 
 
133
  func forceIPv4DSN(dsn string) string {
134
  if dsn == "" {
135
  return dsn
@@ -142,7 +144,6 @@ func forceIPv4DSN(dsn string) string {
142
  if host == "" || net.ParseIP(host) != nil {
143
  return dsn
144
  }
145
- port := u.Port()
146
  ips, err := net.LookupIP(host)
147
  if err != nil {
148
  return dsn
@@ -157,11 +158,9 @@ func forceIPv4DSN(dsn string) string {
157
  if v4 == "" {
158
  return dsn
159
  }
160
- if port != "" {
161
- u.Host = net.JoinHostPort(v4, port)
162
- } else {
163
- u.Host = v4
164
- }
165
  return u.String()
166
  }
167
 
 
125
  return dsn
126
  }
127
 
128
+ // forceIPv4DSN keeps the DSN hostname (required for TLS SNI / pooler routing)
129
+ // but adds a hostaddr=<IPv4> parameter so lib/pq dials the resolved IPv4
130
+ // address instead. Container runtimes (HF Spaces, many CI/cloud networks)
131
+ // frequently have no IPv6 route; a hostname whose DNS returns only an AAAA
132
+ // record first then fails to connect ("network is unreachable"). Never replace
133
+ // the hostname with an IP — Supavisor (Supabase pooler) routes tenants by SNI,
134
+ // and lib/pq uses `host` for TLS server-name verification.
135
  func forceIPv4DSN(dsn string) string {
136
  if dsn == "" {
137
  return dsn
 
144
  if host == "" || net.ParseIP(host) != nil {
145
  return dsn
146
  }
 
147
  ips, err := net.LookupIP(host)
148
  if err != nil {
149
  return dsn
 
158
  if v4 == "" {
159
  return dsn
160
  }
161
+ q := u.Query()
162
+ q.Set("hostaddr", v4)
163
+ u.RawQuery = q.Encode()
 
 
164
  return u.String()
165
  }
166