fix: prevent socket leak in TunnelManager#682
Open
vbragaru wants to merge 1 commit intodanielpaulus:mainfrom
Open
fix: prevent socket leak in TunnelManager#682vbragaru wants to merge 1 commit intodanielpaulus:mainfrom
vbragaru wants to merge 1 commit intodanielpaulus:mainfrom
Conversation
… and adding exponential backoff The TunnelManager was creating socket connections for every device on every UpdateTunnels call, including network-connected devices that can never establish tunnels. This caused thousands of orphaned Unix sockets over time. Changes: - Skip network-connected devices (ConnectionType == "Network") since they cannot establish tunnels - Track devices that fail to connect and apply exponential backoff (30s, 60s, 120s, up to 5 min max) before retrying - Clean up failed device tracking when devices disconnect to allow fresh retry on reconnect - Remove devices from failed list when tunnel connection succeeds This fixes a memory/socket leak that could accumulate thousands of orphaned Unix sockets to /var/run/usbmuxd when many network devices are discovered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
TunnelManager.UpdateTunnels()function was creating socket connections to/var/run/usbmuxdfor every device on every call, includingnetwork-connected devices that can never establish tunnels. This caused thousands of orphaned Unix sockets to accumulate over time.
Root cause:
ListDevices()returns all devices including 50+ network-connected devicesm.tunnels, it callsstartTunnel()which creates socket connections viaios.GetProductVersion()UpdateTunnels()call retries the same failing devicesEvidence: After running overnight,
lsofshowed 3000+ orphaned Unix sockets:Busymate 94207 v 5u unix 0x5bcac11ae229dddf ->(none)
Busymate 94207 v 6u unix 0x1c4c7d88a25e315b ->(none)
... (3000+ more)
Solution
Skip network-connected devices - They cannot establish tunnels anyway (
ConnectionType == "Network")Track failed devices with exponential backoff - Instead of retrying every cycle:
Clean up on disconnect - Remove device from failed list when it disconnects, allowing fresh retry on reconnect
Clean up on success - Remove device from failed list when tunnel succeeds
Testing