Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
A-lullaby opened this issue Jan 4, 2023 · 8 comments
Closed

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

A-lullaby opened this issue Jan 4, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@A-lullaby
Copy link

0b147dd43d584ca6cfe760f70fe92fe

@liudf0716 liudf0716 added the bug Something isn't working label Jan 4, 2023
@liudf0716
Copy link
Owner

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

@helintongh
Copy link
Collaborator

helintongh commented Jan 4, 2023

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

@helintongh
Copy link
Collaborator

在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
Copy link
Owner

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

@A-lullaby
Copy link
Author

A-lullaby commented Jan 5, 2023 via email

@liudf0716
Copy link
Owner

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

@A-lullaby
Copy link
Author

A-lullaby commented Jan 5, 2023 via email

liudf0716 added a commit that referenced this issue Jan 5, 2023
#19

Signed-off-by: Dengfeng Liu <[email protected]>
@liudf0716
Copy link
Owner

liudf0716 commented Jan 5, 2023

是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;
}

原代码处理起来有问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants