Skip to content

Commit 7f0d9e1

Browse files
h4x3rotabclaude
andcommitted
fix(consul-postgres-ha): drop spurious 's' suffix from gateway URLs to plain-HTTP backends
The dstack gateway uses two different URL conventions: <app-id>-<port>.<gw> gateway terminates TLS, forwards plain HTTP <app-id>-<port>s.<gw> gateway TLS pass-through, backend speaks TLS Consul's HTTP API binds plain HTTP on 127.0.0.1, so the consul_ui output and rollout.sh's CONSUL_BASE need the no-'s' form. The 's' form silently fails permanently — early errors look like 'gateway not yet routing,' which trivially mistakes a config bug for a provisioning delay (this is what made us think the gateway took 6+ minutes to come up; it never would have, with the wrong suffix). Also adds a 'dstack gateway URL convention' note to README.md so future readers don't fall into the same trap. Empirically confirmed via a minimal reproducer (separate worktree): trivial nginx CVMs reach 200 in 84-112s end-to-end with the correct suffix; the wrong suffix never reaches 200. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d76f2dd commit 7f0d9e1

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

consul-postgres-ha/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ Once apply finishes, the cluster is HA Postgres on
5959
through any worker's `127.0.0.1:18703+ordinal` (forwarded by mesh-conn
6060
to whichever CVM Patroni elected leader).
6161

62+
### dstack gateway URL convention
63+
64+
Two forms, easy to confuse:
65+
66+
| Form | Behavior | Use when |
67+
|---|---|---|
68+
| `<app-id>-<port>.<gateway-domain>` | Gateway terminates TLS using a pre-issued wildcard cert and forwards plain HTTP to `<port>` on the CVM. | The backend speaks plain HTTP (Consul HTTP API, Patroni REST, webdemo, etc.). |
69+
| `<app-id>-<port>s.<gateway-domain>` | Gateway does TLS pass-through — encrypted bytes go straight to `<port>`. | The backend speaks TLS itself (Envoy public mTLS listener on `:21000`). |
70+
71+
Picking the wrong form fails permanently. Plain-HTTP backend with the
72+
`s` form yields `SSL_ERROR_SYSCALL` early and `wrong version number`
73+
once routing is live; trivially mistakable for a transient gateway
74+
provisioning delay. If the URL doesn't work after ~2 min from CVM
75+
ready, suspect the suffix.
76+
6277
## What's in this directory
6378

6479
```

consul-postgres-ha/cluster-example/cluster.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,10 @@ output "coordinator_app_ids" { value = { for k, c in phala_app.coordinator : k =
270270
output "worker_app_ids" { value = { for k, w in phala_app.worker : k => w.app_id } }
271271
output "consul_ui" {
272272
# Any coordinator's HTTP port serves the UI. Pick coord-0 by convention.
273-
value = "https://${phala_app.coordinator["0"].app_id}-${local.coordinator_http_port_first}s.${var.gateway_domain}/ui"
273+
# `<port>` (no trailing 's') = gateway terminates TLS using the wildcard
274+
# cert and forwards plain HTTP to the backend. Consul HTTP binds plain
275+
# HTTP on 127.0.0.1, so this is the right convention. The `<port>s`
276+
# form is for TLS pass-through where the backend speaks TLS itself
277+
# (e.g. Envoy public mTLS on :21000).
278+
value = "https://${phala_app.coordinator["0"].app_id}-${local.coordinator_http_port_first}.${var.gateway_domain}/ui"
274279
}

consul-postgres-ha/cluster-example/rollout.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ resolve_consul_base() {
5252
echo "ERROR: terraform output coordinator_app_id failed; run terraform apply at least once" >&2
5353
exit 1
5454
fi
55-
CONSUL_BASE="https://${coord_id}-${COORDINATOR_HTTP_PORT}s.${GATEWAY_DOMAIN}"
55+
# `<port>` (no trailing 's') — gateway terminates TLS, backend is
56+
# plain HTTP. The `<port>s` pass-through form is for backends that
57+
# speak TLS themselves; Consul's HTTP API does not.
58+
CONSUL_BASE="https://${coord_id}-${COORDINATOR_HTTP_PORT}.${GATEWAY_DOMAIN}"
5659
}
5760

5861
consul_members_alive() {

0 commit comments

Comments
 (0)