-
Notifications
You must be signed in to change notification settings - Fork 1
Warn when an outbound frame push fails #128
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
Open
douglaseel
wants to merge
8
commits into
main
Choose a base branch
from
douglas/metadata-round-trip-every-session
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−2
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c60acf
Warn when an outbound frame push fails
douglaseel d80ffe6
Make the integration job say where it stalls
douglaseel 39ee6e8
Isolate creating a second peer connection
douglaseel e5fdaf8
Run the isolation file first, in its own invocation
douglaseel 2e7b282
Build the first peer connection up before creating the second
douglaseel 7dd53f1
Give the second peer connection the observer the runtime uses
douglaseel ced6081
Trace the real negotiation instead of replicating it
douglaseel 1af8dd6
Probe the GIL deadlock the loopback stalls on
douglaseel 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
86 changes: 86 additions & 0 deletions
86
tests/integration/transport/webrtc/test_gil_signalling_deadlock.py
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,86 @@ | ||
| """Confirm on the runner why the loopback stops inside ``create_peer_connection``. | ||
|
|
||
| The loopback stalls there and never returns: the last log line before the | ||
| faulthandler dump is the one immediately preceding the call, and the only other | ||
| thread in the dump has a Python thread state with no Python frame — a native | ||
| thread waiting to enter Python. | ||
|
|
||
| That is a deadlock between the GIL and libwebrtc's signalling thread. The | ||
| installed ``reactor_webrtc`` holds the GIL while it creates a peer connection, | ||
| and creating one is a proxy call: it is posted to the signalling thread and the | ||
| caller blocks until it finishes. The loopback's stand-in client is gathering ICE | ||
| candidates at that exact moment, and each candidate is delivered by the | ||
| signalling thread into a Python callback. So the creating thread waits for the | ||
| signalling thread while the signalling thread waits for the GIL, and neither can | ||
| be interrupted, because the creating thread is in native code and never yields. | ||
|
|
||
| This test drives that collision directly, with no tracks, negotiation, media or | ||
| frame metadata involved — a candidate callback parked in Python, then one call. | ||
| It runs in a subprocess, because the deadlock cannot be observed from inside the | ||
| process that is stuck: a watchdog thread would need the GIL the stuck caller | ||
| holds. A timeout turns the hang into a failure. | ||
|
|
||
| Failing here means the deadlock is in the binding rather than in anything this | ||
| package does with it. It is a probe, not a regression test — the fix and its | ||
| permanent test belong to ``reactor-webrtc``, and this file goes away with them. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| import sys | ||
| import textwrap | ||
|
|
||
| import pytest | ||
|
|
||
| pytest.importorskip("reactor_webrtc") | ||
|
|
||
| _TIMEOUT_S = 45 | ||
|
|
||
| _PROBE = textwrap.dedent(""" | ||
| import asyncio, threading, time | ||
| import reactor_webrtc as rw | ||
|
|
||
| factory = rw.PeerConnectionFactory() | ||
|
|
||
| # Fires on the signalling thread. The sleep releases the GIL, so the main | ||
| # thread is free to take it, and the callback then needs it back to return | ||
| # into native code — the state a caller holding the GIL traps it in. | ||
| entered = threading.Event() | ||
|
|
||
| def hold_the_signalling_thread(_candidate): | ||
| entered.set() | ||
| time.sleep(2.0) | ||
|
|
||
| async def main(): | ||
| observer = rw.PeerConnectionObserver() | ||
| observer.on_ice_candidate = hold_the_signalling_thread | ||
| first = factory.create_peer_connection(rw.RtcConfiguration(), observer) | ||
| first.add_transceiver(rw.MediaKind.Video, rw.TransceiverDirection.RecvOnly) | ||
| offer = await first.create_offer() | ||
| await first.set_local_description(offer) | ||
| assert entered.wait(30), "no ICE candidate was delivered" | ||
| factory.create_peer_connection(rw.RtcConfiguration(), rw.PeerConnectionObserver()) | ||
|
|
||
| asyncio.run(main()) | ||
| print("returned") | ||
| """) | ||
|
|
||
|
|
||
| def test_creating_a_peer_connection_returns_while_a_candidate_callback_is_in_flight() -> None: | ||
| """Create a peer connection with the signalling thread parked in Python.""" | ||
| try: | ||
| done = subprocess.run( | ||
| [sys.executable, "-c", _PROBE], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=_TIMEOUT_S, | ||
| ) | ||
| except subprocess.TimeoutExpired: | ||
| pytest.fail( | ||
| f"create_peer_connection did not return in {_TIMEOUT_S}s: the binding holds " | ||
| f"the GIL across the dispatch to the signalling thread, which is waiting " | ||
| f"for the GIL. This is what stalls the loopback." | ||
| ) | ||
| assert done.returncode == 0, f"probe exited {done.returncode}:\n{done.stderr}" | ||
| assert "returned" in done.stdout |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shoudl be removed, it looks temporary