Skip to content

Commit 0aeecf4

Browse files
authored
Fix gateways with a previously used IP address (#2388)
1 parent e125dff commit 0aeecf4

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/dstack/_internal/server/background/tasks/process_gateways.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,13 @@ async def process_submitted_gateways():
5454

5555

5656
async def _remove_inactive_connections():
57-
connections = await gateway_connections_pool.all()
58-
ip_addresses = [c.ip_address for c in connections]
5957
async with get_session_ctx() as session:
6058
res = await session.execute(
61-
select(GatewayComputeModel).where(
62-
GatewayComputeModel.ip_address.in_(ip_addresses),
63-
GatewayComputeModel.active == False,
64-
)
59+
select(GatewayComputeModel.ip_address).where(GatewayComputeModel.active == True)
6560
)
66-
removed_connections = res.scalars().all()
67-
for conn in removed_connections:
61+
active_connection_ips = set(res.scalars().all())
62+
for conn in await gateway_connections_pool.all():
63+
if conn.ip_address not in active_connection_ips:
6864
await gateway_connections_pool.remove(conn.ip_address)
6965

7066

0 commit comments

Comments
 (0)