yiliangyl opened a new issue, #2812: URL: https://github.com/apache/brpc/issues/2812
在使用 stream rpc 时,发现会 coredump 在 Stream::Cosume 方法里 `s->_options.handler->on_closed(s->id());` 这一行: ```cpp int Stream::Consume(void *meta, bthread::TaskIterator<butil::IOBuf*>& iter) { Stream* s = (Stream*)meta; s->StopIdleTimer(); if (iter.is_queue_stopped()) { // ... if (s->_options.handler != NULL) { // ... s->_options.handler->on_closed(s->id()); ``` 然后看到 StreamOptions 里 StreamInputHandler(下面简写为 handler)是通过普通指针传入,同时在 Stream::Create 方法里通过拷贝的方式拿到 options: ```cpp int StreamCreate(StreamIds& request_streams, int request_stream_size, Controller & cntl, const StreamOptions* options) { // ... StreamOptions opt; if (options != NULL) { opt = *options; } ``` 随之让消息通过 Stream::Consume 函数异步消费。 在个人代码中,使用了智能指针来析构 handler(。从结果来看,由于指针拷贝,`s->_options.handler` 并不会为 NULL,而 handler 已经析构了,但仍会执行 Stream::Consume 方法,所以导致 coredump。看了一圈似乎没有接管 handler 生命周期的方法,也没有告知能安全析构 handler 的方法。所以请问下,什么时候析构 handler 才是安全的?感谢解答 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org