liudf0716 / xfrpc

The xfrpc project is a lightweight implementation of the FRP client written in C language for OpenWRT and IoT systems. It is designed to provide an efficient solution for resource-constrained devices such as OpenWRT routers and IoT devices, which often have limited ROM and RAM space.
GNU General Public License v3.0
712 stars 89 forks source link

程序断网重连出现CPU占满情况 #19

Closed A-lullaby closed 1 year ago

A-lullaby commented 1 year ago

0b147dd43d584ca6cfe760f70fe92fe

liudf0716 commented 1 year ago

应该是在清除client和stream资源时,有死循环被触发

helintongh commented 1 year ago

能否给出详细的操作过程呢? 比如你的配置,操作系统版本等.方便复现然后修复相应的bug

helintongh commented 1 year ago

在uibuntu22.04环境下,测试xfrpc的tcp配置和http配置。分别断网三次down掉网卡又up网卡。xfrpc均能重新连上frps且未出现xfrpc占用cpu100%的bug。

xfrpc配置如下: [common] server_addr = 192.168.157.1 server_port = 7000

[http] type = http local_port = 80 custom_domains = www.example.com

[https] type = https local_port = 443 custom_domains = www.example.com

frps配置如下: [common] bind_port = 7000 vhost_http_port = 80 vhost_https_port = 443 但是当出现如下打印 [7][Wed Jan 4 15:19:36 2023]4852 new client through tcp mux: 5 [7][Wed Jan 4 15:19:36 2023]4852 send plain msg ----> [w: { "run_id": "000C29D72E1E" }] [6][Wed Jan 4 15:21:07 2023]4852 interval [91] greater than heartbeat_timeout [90] [7][Wed Jan 4 15:21:07 2023]4852 free client 5 [6][Wed Jan 4 15:21:07 2023]4852 connect server [192.168.157.1:7000]...

注意最后一行,主线的xfrpc卡在了这最后一行再也无法回连到frps上面。因此猜测原因在于xfrpc一直尝试回连导致cpu占用100%。这个bug可以试下利用另一个线程来监控xfrpc的连接状态超时就重启xfrpc。

liudf0716 commented 1 year ago

是因为有死循环导致,代码有bug导致

A-lullaby commented 1 year ago

不是因为断网重连进入的死循环吗? 

@.***

 

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年1月5日(星期四) 上午9:29 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [liudf0716/xfrpc] 程序断网重连出现CPU占满情况 (Issue #19)

是因为有死循环导致,代码有bug导致

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were assigned.Message ID: @.***>

liudf0716 commented 1 year ago

@A-lullaby 断网会导致循环连接,但有sleep,不会导致cpu 100%

A-lullaby commented 1 year ago

了解了解 

@.***

 

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年1月5日(星期四) 上午9:31 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [liudf0716/xfrpc] 程序断网重连出现CPU占满情况 (Issue #19)

@A-lullaby 断网会导致循环连接,但有sleep,不会导致cpu 100%

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

liudf0716 commented 1 year ago

是uthash宏使用错误的问题,根据chatgpt给出的代码,清楚uthash的代码如下:

struct my_struct {
    int id;
    UT_hash_handle hh;
};

struct my_struct *s, *tmp, *users = NULL;

int main() {
    // Add some elements to the hash table
    for (int i = 0; i < 10; i++) {
        s = malloc(sizeof(struct my_struct));
        s->id = i;
        HASH_ADD_INT(users, id, s);
    }

    // Remove all elements from the hash table
    HASH_ITER(hh, users, s, tmp) {
        HASH_DEL(users, s);
        free(s);
    }
    return 0;
}

原代码处理起来有问题。