Skip to content

Commit 2b12e65

Browse files
authored
Gateway state sync mechanism (#4135)
Introduce a way to reconcile gateway replica state based on the current list of services. This allows newly started or newly recovered gateway replicas to learn about existing services. It also improves fault tolerance, since an unavailable gateway replica no longer blocks the service lifecycle - services and service replicas can still be registered on the remaining healthy gateway replicas. Behavioral details: - Run submission no longer waits for service registration before the run starts provisioning. This has both advantages (provisioning and service registration can happen in parallel) and disadvantages (compute may be provisioned for a service that will be terminated a moment later due to a registration error). This behavior may be revised in the future. - A service or a service replica is terminated with the `gateway_error` termination reason if it failed to be registered on all gateway replicas. - If registration succeeded at least on one gateway replica, registration on the remaining gateway replicas will be retried indefinitely. - Rolling deployments only proceed with terminating a service replica once the replacement replica is successfully registered on all gateway replicas. - Registration and unregistration tracking, including per-gateway-replica registration error messages, is available in events.
1 parent 68dc344 commit 2b12e65

22 files changed

Lines changed: 3838 additions & 672 deletions

File tree

mkdocs/docs/concepts/gateways.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ $ dstack gateway list
174174

175175
- Changing the number of replicas or redeploying replicas is not supported.
176176
- HTTPS is only supported for AWS gateways with the `acm` [certificate type](#certificate). For other gateways, use an external load balancer for TLS termination.
177-
- An unavailable gateway replica prevents any new services or service replicas from being added.
178177
- All replicas are bound to the same backend and region.
179178
- At most 3 replicas are allowed per gateway.
180179

src/dstack/_internal/core/models/runs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class RunTerminationReason(str, Enum):
9494
STOPPED_BY_USER = "stopped_by_user"
9595
ABORTED_BY_USER = "aborted_by_user"
9696
SERVER_ERROR = "server_error"
97+
GATEWAY_ERROR = "gateway_error"
9798

9899
def to_job_termination_reason(self) -> "JobTerminationReason":
99100
"""
@@ -107,6 +108,7 @@ def to_job_termination_reason(self) -> "JobTerminationReason":
107108
self.STOPPED_BY_USER: JobTerminationReason.TERMINATED_BY_USER,
108109
self.ABORTED_BY_USER: JobTerminationReason.ABORTED_BY_USER,
109110
self.SERVER_ERROR: JobTerminationReason.TERMINATED_BY_SERVER,
111+
self.GATEWAY_ERROR: JobTerminationReason.TERMINATED_BY_SERVER,
110112
}
111113
return mapping[self]
112114

@@ -118,6 +120,7 @@ def to_status(self) -> "RunStatus":
118120
self.STOPPED_BY_USER: RunStatus.TERMINATED,
119121
self.ABORTED_BY_USER: RunStatus.TERMINATED,
120122
self.SERVER_ERROR: RunStatus.FAILED,
123+
self.GATEWAY_ERROR: RunStatus.FAILED,
121124
}
122125
return mapping[self]
123126

@@ -126,6 +129,8 @@ def to_error(self) -> Optional[str]:
126129
return "retry limit exceeded"
127130
elif self == RunTerminationReason.SERVER_ERROR:
128131
return "server error"
132+
elif self == RunTerminationReason.GATEWAY_ERROR:
133+
return "gateway error"
129134
else:
130135
return None
131136

0 commit comments

Comments
 (0)