diff --git a/CHANGELOG.md b/CHANGELOG.md index f4ee891..c04b06b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ All notable changes to python-libei are recorded here. The format follows ## [Unreleased] +### Fixed + +- **`_wait_for_signal` (used by `InputCaptureSession.wait_for_activation`/ + `wait_for_deactivation`) no longer double-removes its own GLib timeout + source on timeout**, which logged a real GLib warning ("Source ID N was + not found when attempting to remove it") on every timed-out wait. + `GLib.timeout_add`'s callback returns `False`, which already deregisters + the source; the cleanup `finally` block called `GLib.source_remove` on it + again unconditionally. Caught live on the GNOME 50 box (this session's + first real timeout run against a genuine GLib main loop) -- the unit + tests' fake `GLib.source_remove` doesn't reproduce the warning, so it was + invisible to the suite. + ## [0.5.1] - 2026-09-08 ### Fixed diff --git a/src/libei/portal.py b/src/libei/portal.py index e40ca19..ffb8432 100644 --- a/src/libei/portal.py +++ b/src/libei/portal.py @@ -1035,7 +1035,16 @@ def on_timeout() -> bool: try: loop.run() finally: - if timeout_source is not None: + # A fired timeout source has already deregistered itself -- + # on_timeout() returns False, which is GLib's signal to + # remove it -- so only remove it here when the *signal* + # woke the loop instead. Removing it unconditionally trips + # a real GLib warning ("Source ID N was not found when + # attempting to remove it"), confirmed live: it fired on + # every real timeout this session hit, never against + # test_portal.py's fake GLib.source_remove, which just + # clears pending_timeout with no complaint either way. + if timeout_source is not None and not timed_out: GLib.source_remove(timeout_source) finally: connection.signal_unsubscribe(subscription) diff --git a/tests/test_inputcapture.py b/tests/test_inputcapture.py index 0c9c1aa..5c78048 100644 --- a/tests/test_inputcapture.py +++ b/tests/test_inputcapture.py @@ -528,6 +528,28 @@ def test_wait_for_activation_times_out_with_no_signal() -> None: assert excinfo.value.timeout == 0.01 +def test_wait_for_activation_does_not_double_remove_the_timeout_source_on_timeout() -> ( + None +): + # Live-caught 2026-09-08: GLib.timeout_add's callback returning False + # (as on_timeout does) already deregisters the source, so calling + # GLib.source_remove on it again logs a real GLib warning ("Source ID N + # was not found when attempting to remove it"). The fake source_remove + # in install_fake_gi doesn't model that -- it just clears + # pending_timeout either way -- so only asserting the call itself was + # never made catches this; a fake that raised on double-removal would + # have caught it long ago, but reproducing that faithfully needs real + # GLib, which nothing here has. + connection = FakeInputCaptureConnection() + with install_fake_gi(connection): + glib = sys.modules["gi.repository.GLib"] + session = portal.InputCaptureSession.negotiate(connection=connection) + with mock.patch.object(glib, "source_remove") as source_remove: + with pytest.raises(portal.PortalTimeoutError): + session.wait_for_activation(timeout=0.01) + source_remove.assert_not_called() + + def test_wait_for_activation_subscribes_on_this_sessions_own_path() -> None: # A caller managing several sessions on one MainContext must only ever # hear about its own session's activation, not another's.