Files
Alexandr Stelnykovych 42366c0d59 fix(linux): cache socket owners, scan /proc once per socket at a time
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.
2026-10-14 17:51:18 +03:00
..
2024-08-09 18:15:48 +03:00
2024-03-27 16:17:58 +01:00
2025-04-07 14:23:58 +02:00
2024-08-09 18:15:48 +03:00
2024-08-09 18:15:48 +03:00