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

brpc client 开启dummy server 程序core掉 #2896

Open
wudianer opened this issue Feb 19, 2025 · 8 comments
Open

brpc client 开启dummy server 程序core掉 #2896

wudianer opened this issue Feb 19, 2025 · 8 comments

Comments

@wudianer
Copy link

wudianer commented Feb 19, 2025

Describe the bug (描述bug)
程序使用brpc client 访问 server端,当访问contention时

Image 会导致程序出core 。gdb查看是这里的问题

Image

To Reproduce (复现方法)
只要有下载请求 访问contention必现

Versions (各种版本)
OS: centos 7.9
gcc:11
Compiler:
brpc:v1.0.0

@TousakaRin
Copy link
Contributor

可以给一个能复现的demo吗

@wudianer
Copy link
Author

wudianer commented Feb 19, 2025

可以给一个能复现的demo吗

感谢回复 具体场景是客户端http请求下载文件 我们服务接收请求后 调用存储端的sdk读文件并做处理

    ctx->AsyncCallWithAttachment([req, callback = std::move(callback), ctx = std::move(ctx)]() mutable
                                 {  
         ### // brpc回调:
          auto lambda = [ctx](char *data, size_t length) -> size_t
            {
                 if (ctx == nullptr || length == 0) {
                return 0; 
            }
            if(!ctx->readed){
                ctx->readed = true;
                if (ctx->ret_val!=0){
                    LOG_ERROR << "AsyncCall failed";
                    return 0; 
                }
            }
                size_t bytesToWrite = std::min(length, ctx->object_size);
                if (ctx->offset + bytesToWrite > ctx->object_size)
                {
                    bytesToWrite = ctx->object_size - ctx->offset;
                }
        ### //看gdb是当访问contention这里出core 
                ctx->buf.cutn(data, bytesToWrite);  
                ctx->offset += bytesToWrite;
                return bytesToWrite;
            };
            auto resp = HttpResponse::newStreamResponse(lambda, "", CT_APPLICATION_OCTET_STREAM, "", req);
            resp->addHeader("Content-Length", std::to_string(ctx->object_size));
            callback(resp); }); 

然后配置一个dummy_server.port 访问flags ,status ,vars这些没问题 但是访问contention这些就出问题,当然 进程不承接流量 不会有问题

Image

@TousakaRin
Copy link
Contributor

看起来有点像执行到 ctx->buf.cutn() 这句的时候,ctx已经被析构了,

@wudianer
Copy link
Author

wudianer commented Feb 19, 2025

看起来有点像执行到 ctx->buf.cutn() 这句的时候,ctx已经被析构了,

ctx是一个智能指针 auto ctx = std::make_shared(object_size); 并且 如果不用brpc的异步回调处理数据 用同步的方式 也是上述的core的位置

@TousakaRin
Copy link
Contributor

有可以运行的例子吗

@wudianer
Copy link
Author

有可以运行的例子吗

您的意思是说 要一个源码示例嘛

@TousakaRin
Copy link
Contributor

有可以运行的例子吗

您的意思是说 要一个源码示例嘛

对的

@wudianer
Copy link
Author

有可以运行的例子吗

您的意思是说 要一个源码示例嘛

对的

代码没有上传到公共仓库 但是与brpc核心的流程就是上面的例子了 还有就是 ctx是一个 sdk的实例 AsyncCallWithAttachment方法内部

>     pb::Closure* done = brpc::NewCallback(&ReadObjectWithAttachmentCb, serv_addr,, request, response, cntl, closure, buf);
>     stub.Read(serv_addr, request.get(), response.get(), cntl.get(), done, &options);
```通过这种实例与server端交互 看着主流程也没啥问题 不通过dummy server监控 也能跑出不错的业务带宽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants