Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/sentry/testutils/pytest/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from os import environ, path
from urllib.parse import urlparse

import docker.errors
import ephemeral_port_reserve
import pytest
import requests
Expand Down Expand Up @@ -139,7 +140,18 @@ def relay_server(relay_server_setup, settings):
with get_docker_client() as docker_client:
container_name = _relay_server_container_name()
_remove_container_if_exists(docker_client, container_name)
container = docker_client.containers.run(**options)
# Docker may not release the host port binding immediately after
# container removal; retry to ride out the race window.
for attempt in range(5):
try:
container = docker_client.containers.run(**options)
break
except docker.errors.APIError as e:
if "address already in use" in str(e) and attempt < 4:
time.sleep(1 * 1.5**attempt)
_remove_container_if_exists(docker_client, container_name)
continue
raise

_log.info("Waiting for Relay container to start")

Expand Down
Loading