mirror of
https://github.com/safing/portmaster.git
synced 2026-12-04 09:38:21 +00:00
42366c0d59
Issue: Finding the process of a socket walks /proc/<pid>/fd of every process of the user. The result was stored on the socket-table entry, which is replaced on every table refresh (up to 100 per second), so every new connection of a long-lived socket - a torrent's DHT socket, a listening socket, a resolver - triggered a full scan. Under a burst, thousands of scans ran at once and slowed each other down until packets timed out while their lookup was still running; the connections with a lookup in flight were the memory growth reported in #2233. Change: - Cache the found owner by socket inode for 1-2 s (two generations, lazy rotation, bounded size). A cache hit is only used if the PID is still in the user's PID list, so an exited owner is scanned for again. - Run at most one scan per socket at a time (singleflight). Lookups that arrive while a scan runs wait for its result instead of scanning too. Without this the first scan under a burst never finished.