-
Notifications
You must be signed in to change notification settings - Fork 14
Retry connect() on SFU full by requesting a different SFU #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f68bbf7
feat: preserve SFU error code in SignalingError
aliev bd33f67
feat: add SfuJoinError and retryable error detection in connect_webso…
aliev 369a085
feat: pass migrating_from to coordinator join request
aliev 8678b80
feat: retry connect() on SFU full by requesting a different SFU
aliev 8f73de8
chore: remove dead retry code replaced by error-code-based detection
aliev 6a352b9
style: remove extra blank line left after dead code removal
aliev 536f95d
style: apply ruff formatting
aliev 311447d
style: apply ruff formatting to test_signaling.py
aliev 61da611
refactor: extract _handle_join_failure from connect() retry loop
aliev 2cf9b73
refactor: use exp_backoff with sleep parameter in connect() retry loop
aliev bacbce1
refactor: move ConnectionManager import to module level in tests
aliev 5af1ac6
Merge branch 'main' into feat/retry-connect-on-sfu-full
aliev 9db988d
fix: close ws_client on connect_websocket failure to prevent thread leak
aliev 6a34c05
test: mock exp_backoff in connect() tests to avoid real sleep delays
aliev 857d3c7
chore: update uv.lock
aliev efd9b09
refactor: use pytest fixture for ConnectionManager setup in tests
aliev ab8a27c
refactor: use fixtures in test_connection_utils, snapshot mutable lis…
aliev df9a07c
test: assert ws_client cleanup behavior, not just retry count
aliev de6d889
refactor: remove sleep param from exp_backoff, keep sleep in caller
aliev 23dc2f2
refactor: remove redundant _instant_backoff test helper
aliev dd99813
test: assert retry count in exhausted-retries test
aliev 66708cd
refactor: extract _connect_with_sfu_reassignment from connect()
aliev 41ec538
chore: add utility script for testing SFU connection and retry behavior
aliev 33d18b9
refactor: extract last_failed variable for clarity in _connect_internal
aliev 2a75703
refactor: raise directly from except instead of tracking last_error
aliev ab392f2
feat: validate max_join_retries and extract patched_dependencies helper
aliev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Utility script for testing SFU connection and retry behavior. | ||
|
|
||
| Connects to a call as a given user and logs each step of the connection | ||
| process — useful for verifying SFU assignment, retry on transient errors | ||
| (e.g. SFU_FULL), and reassignment via the coordinator. | ||
|
|
||
| Environment variables | ||
| --------------------- | ||
| STREAM_API_KEY — Stream API key (required) | ||
| STREAM_API_SECRET — Stream API secret (required) | ||
| STREAM_BASE_URL — Coordinator URL (default: Stream cloud). | ||
| Set to http://127.0.0.1:3030 for a local coordinator. | ||
| USER_ID — User ID to join as (default: "test-user"). | ||
| CALL_TYPE — Call type (default: "default"). | ||
| CALL_ID — Call ID. If not set, a random UUID is generated. | ||
|
|
||
| Usage | ||
| ----- | ||
| # Connect via cloud coordinator | ||
| STREAM_API_KEY=... STREAM_API_SECRET=... \\ | ||
| uv run --extra webrtc python scripts/test_sfu_connect.py | ||
|
|
||
| # Connect via local coordinator | ||
| STREAM_BASE_URL=http://127.0.0.1:3030 \\ | ||
| uv run --extra webrtc python scripts/test_sfu_connect.py | ||
| """ | ||
|
|
||
| import asyncio | ||
| import logging | ||
| import os | ||
| import uuid | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| from getstream import AsyncStream | ||
| from getstream.models import CallRequest | ||
| from getstream.video.rtc import ConnectionManager | ||
|
|
||
| load_dotenv() | ||
|
|
||
| logging.basicConfig( | ||
| level=logging.INFO, | ||
| format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||
| ) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def run(): | ||
| base_url = os.getenv("STREAM_BASE_URL") | ||
| user_id = os.getenv("USER_ID", "test-user") | ||
| call_type = os.getenv("CALL_TYPE", "default") | ||
| call_id = os.getenv("CALL_ID", str(uuid.uuid4())) | ||
|
|
||
| logger.info("Configuration:") | ||
| logger.info(f" Coordinator: {base_url or 'cloud (default)'}") | ||
| logger.info(f" User: {user_id}") | ||
| logger.info(f" Call: {call_type}:{call_id}") | ||
|
|
||
| client_kwargs = {} | ||
| if base_url: | ||
| client_kwargs["base_url"] = base_url | ||
|
|
||
| client = AsyncStream(timeout=10.0, **client_kwargs) | ||
|
|
||
| call = client.video.call(call_type, call_id) | ||
| logger.info("Creating call...") | ||
| await call.get_or_create(data=CallRequest(created_by_id=user_id)) | ||
| logger.info("Call created") | ||
|
|
||
| cm = ConnectionManager( | ||
| call=call, | ||
| user_id=user_id, | ||
| create=False, | ||
| ) | ||
|
|
||
| logger.info("Connecting to SFU...") | ||
|
|
||
| async with cm: | ||
| join = cm.join_response | ||
| if join and join.credentials: | ||
| logger.info(f"Connected to SFU: {join.credentials.server.edge_name}") | ||
| logger.info(f" WS endpoint: {join.credentials.server.ws_endpoint}") | ||
| logger.info(f" Session ID: {cm.session_id}") | ||
|
|
||
| logger.info("Holding connection for 3s...") | ||
| await asyncio.sleep(3) | ||
|
|
||
| logger.info("Leaving call") | ||
|
|
||
| logger.info("Done") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(run()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.