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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ All notable changes to python-libei are recorded here. The format follows
tests' fake `GLib.source_remove` doesn't reproduce the warning, so it was
invisible to the suite.

- **`_request` had the identical double-remove bug as its sibling above,
never fixed alongside it.** `_request` backs every Request-returning
RemoteDesktop/InputCapture call (`CreateSession`, `SelectDevices`,
`Start`, `GetZones`, `SetPointerBarriers`) -- far more heavily used than
`_wait_for_signal` -- so this covers the single most realistic timeout
scenario in the module: a consent dialog nobody answers. Found by a
self-review sweep after the `_wait_for_signal` fix, not live; fixed the
same way, with a test mirroring `test_inputcapture.py`'s existing one for
`_wait_for_signal`.

## [0.5.1] - 2026-09-08

### Fixed
Expand Down
14 changes: 10 additions & 4 deletions src/libei/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,16 @@ def subscribe(path: str) -> None:
try:
loop.run()
finally:
# Removing an already-fired one-shot source is harmless
# (GLib warns at most); leaking a live one holds a reference
# to this closure and fires it into a dead loop later.
GLib.source_remove(timeout_source)
# on_timeout() returns False, which is GLib's own signal to
# deregister a fired one-shot source -- removing it again
# here trips a real "Source ID N was not found when
# attempting to remove it" warning, the same bug already
# fixed for _wait_for_signal below. Only remove it when the
# *Response* woke the loop instead; leaving a live source in
# that case holds a reference to this closure and fires it
# into a dead loop on some later request.
if not timed_out:
GLib.source_remove(timeout_source)
finally:
for subscription in subscriptions:
connection.signal_unsubscribe(subscription)
Expand Down
44 changes: 44 additions & 0 deletions tests/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,50 @@ def call_sync(
assert excinfo.value.timeout == 0.01


def test_request_does_not_double_remove_the_timeout_source_on_timeout() -> None:
# The same bug already fixed in _wait_for_signal (see
# test_inputcapture.py's test of the same name): on_timeout() returning
# False already deregisters a one-shot GLib timeout source, so calling
# GLib.source_remove on it again logs a real "Source ID N was not found
# when attempting to remove it" warning. _request() had this fixed only
# in its sibling, never here, even though _request is the far more
# heavily used of the two (CreateSession, SelectDevices, Start, GetZones,
# SetPointerBarriers all go through it) -- so this is the single most
# realistic timeout scenario in the module: a consent dialog nobody
# answers. The fake source_remove doesn't model an already-deregistered
# source (it just clears pending_timeout either way), so only asserting
# the call was never made catches this.
class SilentConnection(FakeConnection):
def call_sync(
self,
bus_name: Any,
object_path: Any,
interface: Any,
method: str,
parameters: FakeVariant | None,
reply_type: Any,
flags: Any,
timeout: Any,
cancellable: Any,
) -> FakeReply:
self.calls.append(
(method, None if parameters is None else parameters.value)
)
if method == "Get":
return FakeReply((self.version,))
return FakeReply(()) # accepted, but no Response ever fires

connection = SilentConnection()
with install_fake_gi(connection):
glib = sys.modules["gi.repository.GLib"]
with mock.patch.object(glib, "source_remove") as source_remove:
with pytest.raises(portal.PortalTimeoutError):
portal.RemoteDesktopSession.negotiate(
connection=connection, timeout=0.01
)
source_remove.assert_not_called()


def test_close_closes_an_unclaimed_eis_fd() -> None:
# The fd arrives dup'd and owned. If nobody ever reads `eis_fd` (so it
# was never handed to a Sender, which would close it itself), nothing
Expand Down
Loading