Comments (2)
你可能认为这样的调用轨迹会造成死锁:
- RpcClientImpl::StopStreams() ,加锁 _stream_map_lock,然后close所有stream;
- RpcClientStream::on_closed()中,调用所有未完成的cntl->Done();
- Done()中调用用户回调函数,用户在回调函数中再次发送请求,调用RpcClientImpl::CallMethod();
- CallMethod()中调用RpcClientImpl::FindOrCreateStream(),对_stream_map_lock加锁——由于1中已经加锁,造成死锁。
实际上,这里不会死锁,因为:
- 用户callback总是在callback_thread中执行的,即1、2和3、4不会在同一个线程中完成,不会死锁,只会竞锁。可以查看RpcChannelImpl::DoneCallback()函数,这里是真正调用用户callback的地方,如果是异步调用的话(用户设置了callback函数),Done最终是调用到了这里。里面将对用户callback的调用post到了CallbackThreadGroup中。
- RpcClientImpl::_is_running从一定程度上避免了上述问题的发生:
- RpcClientImpl::CallMethod()首先会检查is_runing状态;
- RpcClientImpl::StopStreams()只在RpcClientImpl::Stop()中被调用,而且调用之前,已经设置了“_is_running = false”;
- 但这里不能完全保证,只是一种优化:如果要完全保证,需要在RpcClientImpl::CallMethod()中对_start_stop_lock加锁,与RpcClientImpl::Stop()中对_is_runing的设置形成互斥。在实现时,考虑到加锁会影响性能,在保证不出问题的情况下,CallMethod()中并没有对_start_stop_lock加锁。
谢谢提醒,是否解释了你的疑问?
from sofa-pbrpc.
Confirm with Zuoyan, this scene will not happened. Please close it.
Thank you.
from sofa-pbrpc.
Related Issues (20)
- sofa-server端耗时异常
- sofa-client请求超时之后不关闭tcp连接导致同一个连接上请求连续超时 HOT 1
- try_start_receive是否可以省略_receive_token
- RpcServerMessageStream和RpcMessageStream类是否可抽取公共父类
- boost async_write_some可否用async_write替换 HOT 1
- sofa-pbrpc 需要引入可配置参数
- 客户端超时设置 HOT 2
- sofa-pbrpc-client health超时
- Too many threads in sofa ,how use epoll to overlap large number of socket events HOT 2
- sofa使用snapy压缩请求体大小为100+K时解压缩出错 HOT 5
- GOOGLE_ATTRIBUTE_DEPRECATED 替换成 __attribute__((deprecated)) HOT 2
- 什么时候支持window? HOT 2
- CPU使用问题 HOT 3
- 内存问题 HOT 2
- server如何主动向client发送消息? HOT 1
- bugs on weak memory model arch.(arm/power)
- server端如何主动发消息?
- 关于volatile变量相关的问题
- 有没有这种服务互相调用的方法
- cross compile error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sofa-pbrpc.