当前位置:网站首页>Solve the grpc connection problem. Dial succeeds with transientfailure
Solve the grpc connection problem. Dial succeeds with transientfailure
2022-07-05 11:26:00 【_ Qilixiang】
If help , Welcome to leave your footprints !
Details are as follows
code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 192.168.31.33:9001:
connectex: No connection could be made because the target machine actively refused it."
At this time, the connection status is TransientFailure
Catalog
background
GRPC When establishing a connection between the client and the server, we all know that Dial, When reporting the error, in fact Dial The operation was successful , here err by nil, But the call rpc Interface failed , Reported the wrong .
Phenomenon summary
1, Put both the client and the server on this computer , And when the address is written in the address of this machine, it will also report an error ,Dial success , call rpc Interface failed ;
Dial The connection status when successful is Connecting, call rpc The connection state before interface failure changes to TransientFailure;
What do these two states mean ? Look at the source :
const (
// Idle indicates the ClientConn is idle. Idle Express ClientConn At rest .
Idle State = iota
// Connecting indicates the ClientConn is connecting. Connecting Express ClientConn on connection .
Connecting
// Ready indicates the ClientConn is ready for work. Ready Express ClientConn Ready to work .
Ready
// TransientFailure indicates the ClientConn has seen a failure but expects to recover. TransientFailure Express ClientConn I have seen the failure but hope to recover .
TransientFailure
// Shutdown indicates the ClientConn has started shutting down. Shutdown Express ClientConn Has begun to close .
Shutdown
)
2, Put both the client and the server on this computer , And the address is 127.0.0.1 When it comes to success , call rpc The interface is also successful , Everything is all right ;
3, Put the client and server on different hosts , And the starting service address is written 127.0.0.1、 Write the client connection address to the server ip If you fail, you will make a mistake ,Dial success , call rpc Interface failed ;
It makes people wonder , What is the problem ?
Analyze and solve
When the above phenomena occur , The host of the server has opened the port number 9001 Of tcp port , Therefore, the problem of port opening is eliminated ;
in addition , The client and server can succeed when both are on the machine , But it doesn't succeed on different hosts , It shows that the probability is still the problem of network failure ;
At the same time, grab bags , It is found that there are packets flowing from the client to the server host and the ports are correct , But back and forth are R. and S The marks of are alternating , The server keeps replying to the client R. Indicates that the connection exception has been reset , At the same time, such a reply is actually consistent with the situation when the server does not start the service ;
According to the above phenomenon , It is basically determined that the client does not recognize the start of the server ( In fact, the server starts )
Finally, I checked the code and learned , When starting the service, the listening address is
net.Listen("tcp", fmt.Sprintf("%s:%s", "127.0.0.1", 9001))
The following expressions can be used :
net.Listen("tcp", fmt.Sprintf(":%s", 9001))
net.Listen("tcp", fmt.Sprintf("%s:%s", " This machine IP", 9001))
net.Listen("tcp", fmt.Sprintf("%s:%s", "0.0.0.0", 9001))
Can succeed !
First of all 、 The three service addresses printed after startup are [::]:9001
The second is 192.168.31.33:9001
Summary and appendix
Then sum up the reasons , It's actually 127.0.0.1 Only this machine can be connected successfully at startup , It only works on this machine , Because it is the local loopback address ,
Normal network packets are from 3 Layer into 2 layer , Then send it out , And the packet sent to the loopback address , Directly in IP It's short circuited , That is, to IP Layers are directly IP Layer receiving 、 Don't send it down any more ;
That is to say, you can directly use 127.0.0.1.
1、 If the listening address is 127.0.0.1:port, It means only listening to the data of the loopback interface , That is, the machine sends it to the machine port Port data , Data sent by other hosts cannot be received .
2、 If the listening address is 0.0.0.0:port, It means to monitor the data of all network interfaces , Including loopback interface and other network interfaces , All data sent by this machine and other hosts can be received .
3、 If the listening address is local ip:port, Means to listen to the local computer only ip Corresponding network interface . Only the destination address is local ip The data of .( For the case that this machine is sent to this machine , If the destination host address is 127.0.0.1 be , Don't get , Only if the destination host address is local ip Can receive ).
actually 0.0.0.0 Risk is bigger , It is recommended to use this machine IP Appropriate .
边栏推荐
- shell脚本文件遍历 str转数组 字符串拼接
- In the last process before the use of the risk control model, 80% of children's shoes are trampled here
- [SWT component] content scrolledcomposite
- 力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
- How can edge computing be combined with the Internet of things?
- pytorch训练进程被中断了
- Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
- Zcmu--1390: queue problem (1)
- About the use of Vray 5.2 (self research notes)
- 解决访问国外公共静态资源速度慢的问题
猜你喜欢
Evolution of multi-objective sorting model for classified tab commodity flow
Detailed explanation of MATLAB cov function
About the use of Vray 5.2 (self research notes)
Repair animation 1K to 8K
comsol--三维图形随便画----回转
7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
Intelligent metal detector based on openharmony
基础篇——REST风格开发
[Oracle] use DataGrid to connect to Oracle Database
高校毕业求职难?“百日千万”网络招聘活动解决你的难题
随机推荐
ZCMU--1390: 队列问题(1)
PHP中Array的hash函数实现
7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
Web API配置自定义路由
Stop saying that microservices can solve all problems!
R3live series learning (IV) r2live source code reading (2)
Golang application topic - channel
Evolution of multi-objective sorting model for classified tab commodity flow
购买小间距LED显示屏的三个建议
紫光展锐全球首个5G R17 IoT NTN卫星物联网上星实测完成
2022 Pengcheng cup Web
Dspic33ep clock initialization program
Codeforces Round #804 (Div. 2)
【广告系统】Parameter Server分布式训练
Redis如何实现多可用区?
Ffmpeg calls avformat_ open_ Error -22 returned during input (invalid argument)
解决访问国外公共静态资源速度慢的问题
高校毕业求职难?“百日千万”网络招聘活动解决你的难题
Startup process of uboot:
FreeRTOS 中 RISC-V-Qemu-virt_GCC 的调度时机