zhaodongzhi commented on PR #1774: URL: https://github.com/apache/incubator-brpc/pull/1774#issuecomment-1147002302
解决方案这里采用增加mutex的方式其实和brpc整体很多无锁的设计有点不太搭。。。。最初也考虑过一个无锁的方式但是发现比较麻烦 本质上来说_recycle_flag为true的时候socket不应该被获取到 最初的想法是将Socket::Address和Socket::AddressFailedAsWell中 if (ver1 == VersionOfSocketId(id)) 返回有效socket ptr 改为 if (ver1 == VersionOfSocketId(id) && !m->_recycle_flag) 才返回有效socket ptr【AddressFailedAsWell中再加一个对if (ver1 == VersionOfSocketId(id) + 1)的处理】 使得上述场景下1,2之间其他request无法通过address获取到socket,也就不会再进入SetFailed产生这个少释放一次ref count的问题了 但是这种做法带来的问题是,部分恢复逻辑依赖通过Socket::AddressFailedAsWell获取socket ptr,如果_recycle_flag为true的时候也让Socket::AddressFailedAsWell获取不到有效的ptr同样会导致socket无法恢复,但如果允许Socket::AddressFailedAsWell忽略_recycle_flag,部分代码中有存在类似 SocketUniquePtr ptr; const int rc = Socket::AddressFailedAsWell(handle, &ptr); ptr->ReleaseAdditionalReference(); 的逻辑(例如ChannelBalancer::RemoveAndDestroyChannel),还是会有引发这个问题的风险 可以看下是否还有更优雅的不使用mutex的解决方案? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
