heiher/hev-socks5-tunnel

No limit on Memory consumption for ios < 15 or IPhone 7

Closed this issue · 12 comments

Case: Using hev-socks5-tunnel for ios below 15 or iphone 7 devices causes memory limit exceeded

The library increasingly uses memory and breaks the limit of 15MB of NEPacketTunnelProvider limit.
This causes the extension process to be killed by the ios.

Thread 14: EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=15 MB)

Is there any way to limit the amount of memory used in the library?

I have the same issue. On modern iOS the limit is 50MB but nonetheless can be hit with heavy downloads.

Force close recently inactive sessions, any other ideas?

Couple of questions and ideas:

  1. We may have a setting to limit the max number of simultaneous TCP and UDP sessions and wait before accepting new connections if the pool is full? But I am not entirely sure it's a great idea. I'd have to look into how others do that.
  2. How long do UDP sessions stick around given that UDP is stateless? Can we have a setting for that?
  3. Another challenge is how to measure how much memory a single connection takes?

same here UDP Session make tunnel killed (douyin dns req burst)

is there way disable udp?

Disabling UDP is not possible (required).
If the buffer size and concurrent session count is the problem, is there a way to limit them in conf file?

It's recommended to give up on systems below iOS 15; they're not worth the effort.

As @pronebird mentioned, it is a problem even in ios versions above 15, causing extension to die

The library works well on iOS 15 and above when I use it. Could the insufficient memory issue be due to other third-party proxy protocols not managing memory properly, rather than a problem with this library?

There is a way to limit the number of TCP connections to limit memory usage. The current default value is 1024. I tested 1024 concurrent connections on Linux 64-bit system, which requires about 11M of memory.

https://github.com/heiher/lwip/blob/master/src/ports/include/lwipopts.h#L125

/**
 * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections.
 * (requires the LWIP_TCP option)
 */
#define MEMP_NUM_TCP_PCB                1024

The v2.6.9 allocates TCP buffers on the stack and optimizes the memory footprint, which helps reduce physical memory usage.

The v2.6.9 allocates TCP buffers on the stack and optimizes the memory footprint, which helps reduce physical memory usage.

it seems would crash in my macOS app

The v2.6.9 allocates TCP buffers on the stack and optimizes the memory footprint, which helps reduce physical memory usage.

it seems would crash in my macOS app

Check the task-stack-size: https://github.com/heiher/hev-socks5-tunnel/blob/master/conf/main.yml#L37