heiher / hev-socks5-tunnel

A high-performance tun2socks for Linux/Android/FreeBSD/macOS/iOS/WSL2 (IPv4/IPv6/TCP/UDP)
MIT License
651 stars 132 forks source link

在ios上刷抖音会crash #74

Closed Yewenyu closed 7 months ago

Yewenyu commented 7 months ago

使用这个tun2socks之后,刷其他视频app正常,比如腾讯和爱奇艺,但是刷抖音一段时间后会crash

我用的clash库,不过自行修改了限制最大连接数,达到一定连接数后就会强制关闭比较旧的连接。

不是ios内存限制崩溃。

我用其他tun2socks是正常的。

可是其他tun2socks的速度比这个慢很多。

麻烦您修一修这个bug

tunnel:
  mtu: 8500

socks5:
  port: 7890
  address: ::1
  udp: 'udp'
heiher commented 7 months ago

你好,我需要更多的信息才有可能定位并解决问题。比如:

  1. 该项目如何与ios系统协同工作起来的?
  2. 软件各组件的结构是怎样的?
  3. 崩溃现场的信息。
  4. 有没有简单、高效的复现触发方法?
Yewenyu commented 7 months ago

d5d12efdb3abddbcff1299d7215b97ef 项目结构是这样,使用你的脚步打包成.a文件导入项目,然后传入配置启动 image

这里是启动clash image

崩溃信息只有这样 image

复现方法是刷10到20分钟左右的抖音

heiher commented 7 months ago

关于崩溃现场,有没有比较详细的调用栈信息?(编译一个调试版本的hev-socks5-tunnel.a跑跑看)

Yewenyu commented 7 months ago

关于崩溃现场,有没有比较详细的调用栈信息?(编译一个调试版本的hev-socks5-tunnel.a跑跑看)

请问怎么编译调试版本

heiher commented 7 months ago

在make命令的CFLAGS参数值里加-g -O0

heiher commented 7 months ago

在Android系统上刷抖音目前还不能复现出问题。

Yewenyu commented 7 months ago

在Android系统上刷抖音目前还不能复现出问题。

来了

image
u16_t
pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
{
  const struct pbuf *p;
  u16_t left = 0;
  u16_t buf_copy_len;
  u16_t copied_total = 0;

  LWIP_ERROR("pbuf_copy_partial: invalid buf", (buf != NULL), return 0;);
  LWIP_ERROR("pbuf_copy_partial: invalid dataptr", (dataptr != NULL), return 0;);

  /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
  for (p = buf; len != 0 && p != NULL; p = p->next) {
    if ((offset != 0) && (offset >= p->len)) {
      /* don't copy from this buffer -> on to the next */
      offset = (u16_t)(offset - p->len);
    } else {
      /* copy from this buffer. maybe only partially. */
      buf_copy_len = (u16_t)(p->len - offset);
      if (buf_copy_len > len) {
        buf_copy_len = len;
      }
      /* copy the necessary parts of the buffer */
      MEMCPY(&((char *)dataptr)[left], &((char *)p->payload)[offset], buf_copy_len);
      copied_total = (u16_t)(copied_total + buf_copy_len);
      left = (u16_t)(left + buf_copy_len);
      len = (u16_t)(len - buf_copy_len);
      offset = 0;
    }
  }
  return copied_total;
}
heiher commented 7 months ago

把p及其它所有的结构成员展开看看。

Yewenyu commented 7 months ago

把p及其它所有的结构成员展开看看。

image image
heiher commented 7 months ago

和上面不是同一个上下文?这次出错的地址是什么?

Yewenyu commented 7 months ago

和上面不是同一个上下文?这次出错的地址是什么?

一样的,都是同一个地方崩溃

heiher commented 7 months ago

不是。我需要同一次现场的上下文信息。EXC_BAD_ACCESS地址和pbuf_copy_partial帧的各个变量的成员展开数据。

Yewenyu commented 7 months ago

不是。我需要同一次现场的上下文信息。EXC_BAD_ACCESS地址和pbuf_copy_partial帧的各个变量的成员展开数据。

image image
Yewenyu commented 7 months ago
image
heiher commented 7 months ago

感谢协助调试,我这初步猜测了一个可能性,请打上下面的补丁试试看还能否再复现。

diff --git a/src/hev-socks5-session-tcp.c b/src/hev-socks5-session-tcp.c
index 73a43cb..0c4c053 100644
--- a/src/hev-socks5-session-tcp.c
+++ b/src/hev-socks5-session-tcp.c
@@ -307,9 +307,7 @@ hev_socks5_session_tcp_destruct (HevObject *base)
         tcp_recv (self->pcb, NULL);
         tcp_sent (self->pcb, NULL);
         tcp_err (self->pcb, NULL);
-
-        if (tcp_close (self->pcb) != ERR_OK)
-            tcp_abort (self->pcb);
+        tcp_abort (self->pcb);
     }

     if (self->queue)
Yewenyu commented 7 months ago

感谢协助调试,我这初步猜测了一个可能性,请打上下面的补丁试试看还能否再复现。

diff --git a/src/hev-socks5-session-tcp.c b/src/hev-socks5-session-tcp.c
index 73a43cb..0c4c053 100644
--- a/src/hev-socks5-session-tcp.c
+++ b/src/hev-socks5-session-tcp.c
@@ -307,9 +307,7 @@ hev_socks5_session_tcp_destruct (HevObject *base)
         tcp_recv (self->pcb, NULL);
         tcp_sent (self->pcb, NULL);
         tcp_err (self->pcb, NULL);
-
-        if (tcp_close (self->pcb) != ERR_OK)
-            tcp_abort (self->pcb);
+        tcp_abort (self->pcb);
     }

     if (self->queue)

应该可以了,刷了1个小时也没崩

heiher commented 7 months ago

感谢验证,最终修复见 https://github.com/heiher/hev-socks5-tunnel/commit/f81cb6bb5bba6ba1409ba175bdff928cc8f5ad9d (略有差别)