当前位置:网站首页>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 .
边栏推荐
- Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
- Detailed explanation of DDR4 hardware schematic design
- [JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output
- Beego cross domain problem solution - successful trial
- Golang application topic - channel
- About the use of Vray 5.2 (self research notes)
- Oneforall installation and use
- Intelligent metal detector based on openharmony
- How to make full-color LED display more energy-saving and environmental protection
- Characteristics and electrical parameters of DDR4
猜你喜欢

【Oracle】使用DataGrip连接Oracle数据库

Ddrx addressing principle

【广告系统】Parameter Server分布式训练

Intelligent metal detector based on openharmony

基于OpenHarmony的智能金属探测器

【DNS】“Can‘t resolve host“ as non-root user, but works fine as root

Huawei equipment configures channel switching services without interruption

Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022

Stop saying that microservices can solve all problems!
![[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output](/img/96/b8585205b3faf503686c5bbdcecc53.png)
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output
随机推荐
Three paradigms of database
COMSOL--建立几何模型---二维图形的建立
基于Lucene3.5.0怎样从TokenStream获得Token
deepfake教程
Huawei equipment configures channel switching services without interruption
c#操作xml文件
Dspic33ep clock initialization program
跨境电商是啥意思?主要是做什么的?业务模式有哪些?
Paradigm in database: first paradigm, second paradigm, third paradigm
About the use of Vray 5.2 (self research notes) (II)
[first release in the whole network] (tips for big tables) sometimes it takes only 1 minute for 2 hours of SQL operation
[there may be no default font]warning: imagettfbbox() [function.imagettfbbox]: invalid font filename
解决grpc连接问题Dial成功状态为TransientFailure
7.2每日学习4
Summary of websites of app stores / APP markets
DDRx寻址原理
2022 chemical automation control instrument examination questions and online simulation examination
居家办公那些事|社区征文
Intelligent metal detector based on openharmony
R3Live系列学习(四)R2Live源码阅读(2)