当前位置:网站首页>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 .
边栏推荐
猜你喜欢

【爬虫】wasm遇到的bug

如何将 DevSecOps 引入企业?
![[Oracle] use DataGrid to connect to Oracle Database](/img/4f/886378667889f730eaed39b97f0a39.png)
[Oracle] use DataGrid to connect to Oracle Database

DDR4的特性与电气参数

Harbor image warehouse construction

紫光展锐全球首个5G R17 IoT NTN卫星物联网上星实测完成

Summary of thread and thread synchronization under window

DDRx寻址原理

基于OpenHarmony的智能金属探测器

Go language learning notes - analyze the first program
随机推荐
四部门:从即日起至10月底开展燃气安全“百日行动”
An error is reported in the process of using gbase 8C database: 80000305, host IPS long to different cluster. How to solve it?
Leetcode 185 All employees with the top three highest wages in the Department (July 4, 2022)
Ffmpeg calls avformat_ open_ Error -22 returned during input (invalid argument)
[office] eight usages of if function in Excel
How did the situation that NFT trading market mainly uses eth standard for trading come into being?
spark调优(一):从hql转向代码
Stop saying that microservices can solve all problems!
Golang application topic - channel
msfconsole命令大全,以及使用说明
基础篇——基础项目解析
[Oracle] use DataGrid to connect to Oracle Database
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
龙蜥社区第九次运营委员会会议顺利召开
解决readObjectStart: expect { or n, but found N, error found in #1 byte of ...||..., bigger context ..
7.2 daily study 4
c#操作xml文件
Basics - rest style development
What does cross-border e-commerce mean? What do you mainly do? What are the business models?
[advertising system] incremental training & feature access / feature elimination