Skip to content

fix(rpcclient): stop WebDAV mount when the target disconnects - #450

Merged
doronz88 merged 1 commit into
masterfrom
fix/webdav-close-on-disconnect
Aug 23, 2026
Merged

doronz88 merged 1 commit into
masterfrom
fix/webdav-close-on-disconnect

Conversation

@doronz88

Copy link
Copy Markdown
Owner

Problem

The webdav / rpcdav runner blocked on a fresh asyncio.Event() that nothing ever set:

run_in_loop(asyncio.Event().wait())

So when the target went away — device reboot, killed rpcserver, dropped connection — the WebDAV server, the local mount, and the process all stayed up serving errors until the user hit Ctrl-C.

(Mirrors pymobiledevice3's webdav: Close the server when the device disconnects.)

Fix

Wait on the RPC connection instead of a dead event:

  • ClientEvent.TERMINATED (already emitted by CoreClient.rpc_call on ConnectionError) unblocks the instant an in-flight WebDAV request fails.
  • A periodic liveness probe (getpid, every 5 s) catches a disconnect that happens while the mount is idle and no request is in flight — rpc-project has no background reader, so an idle drop is otherwise invisible.

On disconnect we print Connection to <host> lost; stopping. and run the existing teardown (unmount, stop server, close client). Ctrl-C behaviour is unchanged.

Verification

  • New deterministic tests: test_wait_for_disconnect_returns_on_terminated_event (notifier path) and test_wait_for_disconnect_detects_idle_disconnect_via_heartbeat (probe path).
  • Full tests/test_webdav.py passes (25 passed) against a live rpcserver_ios; pyright clean.
  • Manually verified against the vphone: closing the socket under an idle client is detected within one probe interval (~1 s); a TERMINATED notification returns immediately without waiting for the probe.

https://claude.ai/code/session_01X7BxNXzz1dJmtZngoj5kab

The `webdav`/`rpcdav` runner blocked on a fresh `asyncio.Event()` that nothing
ever set, so when the target went away (device reboot, killed rpcserver, dropped
connection) the WebDAV server, local mount, and process all stayed up serving
errors until Ctrl-C.

Wait on the RPC connection instead: `ClientEvent.TERMINATED` unblocks the moment
an in-flight request fails, and a periodic liveness probe (getpid) catches a
disconnect that happens while the mount is idle. On disconnect we print a message
and run the existing teardown (unmount, stop server, close client).

Claude-Session: https://claude.ai/code/session_01X7BxNXzz1dJmtZngoj5kab
@doronz88
doronz88 merged commit 8ab2e6e into master Aug 23, 2026
24 checks passed
@doronz88
doronz88 deleted the fix/webdav-close-on-disconnect branch August 23, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant