Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/libei/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_inputcapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading