当前位置:网站首页>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 .
边栏推荐
- uboot的启动流程:
- Stop saying that microservices can solve all problems!
- The ninth Operation Committee meeting of dragon lizard community was successfully held
- 项目总结笔记系列 wsTax KT Session2 代码分析
- TSQL – identity column, guid, sequence
- 高校毕业求职难?“百日千万”网络招聘活动解决你的难题
- 2022 mobile crane driver examination question bank and simulation examination
- 【Office】Excel中IF函数的8种用法
- SLAM 01. Modeling of human recognition Environment & path
- POJ 3176-Cow Bowling(DP||记忆化搜索)
猜你喜欢
![[Oracle] use DataGrid to connect to Oracle Database](/img/4f/886378667889f730eaed39b97f0a39.png)
[Oracle] use DataGrid to connect to Oracle Database

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

Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report

如何让全彩LED显示屏更加节能环保

无密码身份验证如何保障用户隐私安全?

Repair animation 1K to 8K

NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?

2022 Pengcheng cup Web

【爬虫】charles unknown错误

Harbor镜像仓库搭建
随机推荐
-26374 and -26377 errors during coneroller execution
sklearn模型整理
项目总结笔记系列 wsTax KT Session2 代码分析
[LeetCode] Wildcard Matching 外卡匹配
SET XACT_ABORT ON
Characteristics and electrical parameters of DDR4
Web API配置自定义路由
边缘计算如何与物联网结合在一起?
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
ibatis的动态sql
Harbor image warehouse construction
基于Lucene3.5.0怎样从TokenStream获得Token
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
[advertising system] incremental training & feature access / feature elimination
CDGA|数据治理不得不坚持的六个原则
分类TAB商品流多目标排序模型的演进
go语言学习笔记-分析第一个程序
POJ 3176-Cow Bowling(DP||记忆化搜索)
The ninth Operation Committee meeting of dragon lizard community was successfully held
【Oracle】使用DataGrip连接Oracle数据库