Skip to content

FIX : Resolve reverse tunnel and WiFi proxy leaks on session end or crash#96

Draft
vdanti wants to merge 1 commit into
AppiumTestDistribution:masterfrom
vdanti:fix/robust-proxy-cleanup
Draft

FIX : Resolve reverse tunnel and WiFi proxy leaks on session end or crash#96
vdanti wants to merge 1 commit into
AppiumTestDistribution:masterfrom
vdanti:fix/robust-proxy-cleanup

Conversation

@vdanti

@vdanti vdanti commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Context

When an Android test session ended, crashed, or the Appium server was abruptly terminated, the device was frequently left with its global WiFi proxy config pointed to a dead port and the active ADB reverse tunnel still open. This led to lost internet connectivity on the device and subsequent test run failures due to port collisions.

Implementation

  • Cached ADB Instance & isRealDevice: Modified ProxyOptions to store the active adb instance and the isRealDevice flag in proxyCache. This ensures that even if Appium destroys the session mappings before our cleanup hooks run, the plugin has a valid fallback ADB instance to revert settings.
  • Explicit Reverse Tunnel Teardown: Updated clearProxy to check the cached isRealDevice flag, and if true, explicitly execute removeReverseTunnel on the current proxy port.
  • Process-Level Graceful Exit Handlers: Registered process exit listeners for SIGINT (Ctrl+C) and SIGTERM in the plugin constructor to asynchronously sweep and restore settings for all active proxies in our cache on server stops.
  • Comprehensive onUnexpectedShutdown Lifecycles: Ensured that onUnexpectedShutdown also sweeps any lingering sessions in our internal proxyCache as a safety fallback.

Requirements

  • Self code-review
  • Documentation updated
  • Manual tests performed (self test)

Manual tests

  1. Initiated a session to configure WiFi Proxy and open a reverse tunnel.
  2. Verified that normal teardown (deleteSession) successfully restores WiFi proxy settings to default and closes the ADB reverse tunnel (adb reverse --list is empty).
  3. Simulating driver crash (onUnexpectedShutdown) successfully falls back to cached ADB and restores proxy/closes tunnel.
  4. Sending SIGINT (Ctrl+C) or SIGTERM to the server process successfully triggers the exit handlers to restore WiFi proxy and tear down the ADB reverse tunnel.

@vdanti vdanti changed the title fix: Resolve reverse tunnel and WiFi proxy leaks on session end or crash FIX : Resolve reverse tunnel and WiFi proxy leaks on session end or crash Jun 16, 2026
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