本文将分享Swarmmode中遇到的坑----join节点时,报错:Timeout的详细内容,并且还将对swarm节点什么意思进行详尽解释,此外,我们还将为大家带来关于(node:7584)Unhan
本文将分享Swarm mode中遇到的坑----join节点时,报错:Timeout的详细内容,并且还将对swarm节点什么意思进行详尽解释,此外,我们还将为大家带来关于(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...、android – java.net.SocketTimeoutException:timeout、C# .net 中 Timeout 的处理及遇到的问题、Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by s...的相关知识,希望对你有所帮助。
本文目录一览:- Swarm mode中遇到的坑----join节点时,报错:Timeout(swarm节点什么意思)
- (node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...
- android – java.net.SocketTimeoutException:timeout
- C# .net 中 Timeout 的处理及遇到的问题
- Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by s...
Swarm mode中遇到的坑----join节点时,报错:Timeout(swarm节点什么意思)
在worker节点机器上通过docker swarm join,打算将该节点加入Swarm集群时,报Timeout错误,如下:
Error response from daemon: Timeout was reached before node was joined. The attempt to join the swarm will continue in the background. Use the "docker info" command to see the current swarm status of your node.
解决方向:
方向一:本地时钟
查看要组成集群的所有机器的本地时钟是否相同(大概相同即可, 差几秒不影响)
输入指令: date
图中,第三个时间不同步
修改第三个服务器的本地时钟:
设置系统时间的操作:格式:date 月日时分年.秒
方向二:主机名 (hostname)
在所有要组成集群的机器上输入:hostname 查看主机名
如果,主机名都为:localhost.localdomain,或者主机名都相同,则需要把所有的主机名修改的不一样,比如可以使用本机ip作为主机名
快速修改主机名的方法:
输入: hostnamectl set-hostname <主机名>
方向三:防火墙
CentOS7的防火墙为 firewalld
最主要的是关闭manager机器的防火墙,其他worker机器的最好也关闭
关闭指令:systemctl stop firewalld.service
然后重启一下docker daemon: systemctl restart docker
worker机器上测试2377端口是否通:
1)在manager节点机器上先执行:
docker swarm init --advertise-addr managerIP
(默认占用2377端口)
用来激活2377端口
2)在worker节点机器上执行:
telnet managerIP 2377
如果端口是通的,则可以进行docker swarm join 来将节点加入集群
(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...
记录一次学习node.js犯的低级错误
这里遇到一个这样的问题
express连接mongoose时报错(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out after 30000 ms
连接数据库的代码
1 const mongoose=require(''mongoose'')
2 mongoose.connect(''mongodb://localhost:27017/express1'',{
3 useNewUrlParser: true,
4 useUnifiedTopology: true
5 })
6
7
8 const UserSchema=new mongoose.Schema({
9 username:{type:String},
10 password:{type:String}
11 })
12 const User=mongoose.model(''User'',UserSchema)
13 module.exports = {
14 User
15 }
按照网上教程说不需用启动数据库直接可以连接,可是怎么也连接不上,一直报超时错误,网上查了一大堆的资料,有的说需要什么超级管理员权限,折腾了好久也没搞出来,而且网上这类似的问题很少,看来是没啥人遇到这样的问题,那估计就是我自己哪儿没写对吧,反复排查之后觉得可能还是需要本地启动mongod,然后尝试cmd里面启动mongod,再从新启动项目,终于成功了
android – java.net.SocketTimeoutException:timeout
03-29 12:16:38.997 32066-4018/com.mobile W/System.err: java.net.socketTimeoutException: timeout 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.Okio$3.newTimeoutException(Okio.java:207) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.AsyncTimeout.exit(AsyncTimeout.java:261) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:158) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:46) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:286) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:96) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.RequestBody$2.writeto(RequestBody.java:96) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:704) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:241) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okhttp3.RealCall.execute(RealCall.java:57) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.mobizio.api.BaseApi.sendOkHttpRequest(BaseApi.java:81) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.mobizio.api.BaseApi.doInBackground(BaseApi.java:45) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.mobizio.api.BaseApi.doInBackground(BaseApi.java:30) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:292) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.lang.Thread.run(Thread.java:818) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: Caused by: java.net.socketException: socket is closed 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:759) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okio.Okio$1.write(Okio.java:80) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:155) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: ... 20 more
解决方法
OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(30,TimeUnit.SECONDS); // connect timeout client.setReadTimeout(30,TimeUnit.SECONDS); // socket timeout
C# .net 中 Timeout 的处理及遇到的问题
C# 中 Timeout 的处理
前言
最近在项目中要实现一个功能,是关于 Timeout
的,主要是要在要在 TCP 连接建立的时间 和 整个请求完成的时间,在这两个时间层面上,如果超出了设置的时间,就抛出异常,程序中断。
研究了一下项目的代码中,发现在使用HTTP协议,发送请求时,主要用的是微软的 Microsoft.Net.HttpWebRequest
这个类来发起请求和接收请求的。当时我隐约记得这个类怎么有点熟悉呀,好像还有 WebRequst
和 HttpClient
这两个把,还没开始真正开始去了解Timeout
在HttpWebRequest
中 如何实现的,我先去看了看这三者到底有何不同?
WebRequest , HttpWebRequest , HttpClient
WebRequest 是 一个抽象类,是HttpWebRequest
的父类。是.NET
中请求和获取网络中的数据的一个类。
HttpWebRequest 是WebReques
t 的一个实现,不仅对WebRequest
中的属性和方法进行了支持,而且还有额外的方法通过Http
协议来和服务端交互。
上面那两个现在在微软官方文档上都不推荐使用了,
现在所推荐的是 HttpClient
。由于项目中遗留之前使用的是HttpWebRequest
,所以就在原来的基础上进行实现,何况的是在HttpClient
中没有找到TCP
连接建立的时间属性的设定。
HttpClient 优点自不必多说:
- 连接池
- 一次初始化,整个生命周期的重用
- 和 .Net Core 的融合
- 以及性能的提升等等
虽然说性能可能提升了,如果你这样用,那也是凉凉
using(HttpClient clinet = new HttpClient())
{
var result = await client.GetAsync("http://aspnetmonsters.com");
Console.WriteLine(result.StatusCode);
}
用完 Using
后,调用了IDispose
接口。那下次还是会重新初始化
这样使用就没问题了
private static HttpClient Client = new HttpClient();
Timeout, ReadWriteTimeout
也可能是我英文的理解能力有点差,在开始我就注意到这个类里面的这两个属性,但是我如何也无法和 TCP 建立前所用的连接时间 与 请求完成的时间联系起来。微软官方文档解释如下:
Timeout:
Timeout is the number of milliseconds that a subsequent synchronous request made with the GetResponse method waits for a response, and the GetRequestStream method waits for a stream. The Timeout applies to the entire request and response, not individually to the GetRequestStream and GetResponse method calls. If the resource is not returned within the time-out period, the request throws a WebException with the Status property set to WebExceptionStatus.Timeout.
The Timeout property has no effect on asynchronous requests made with the BeginGetResponse or BeginGetRequestStream method.
ReadWriteTimeout:
The ReadWriteTimeout property is used when writing to the stream returned by the GetRequestStream method or reading from the stream returned by the GetResponseStream method.
Specifically, the ReadWriteTimeout property controls the time-out for the Read method, which is used to read the stream returned by the GetResponseStream method, and for the Write method, which is used to write to the stream returned by the GetRequestStream method.
设置其实是很方便的,如下所示:
HttpWebRequest request = (HttpWebRequest)WebRequest.Creat("<your url>");
//Set timeout to 1s
request.Timeout = 1000;
//Set ReadWriteTimeout to 3000
request.ReadWriteTimeout = 3000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
WebClient.Exception.Timeout 和 OperationCanceledException
最后在捕捉异常的时候,发现了一个很奇怪的地方,就是使用两段代码,却抛出了不同的异常,
第一段代码:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://www.alibabacloud.com");
request.Timeout = 5000;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
HttpWebRequest request2 = (HttpWebRequest) WebRequest.Create("https://www.cnblogs.com");
request2.Timeout = 1;
HttpWebResponse response2 = (HttpWebResponse) request2.GetResponse();
//Exception
/*
Unhandled Exception: System.Net.WebException: The operation has timed out.
at System.Net.HttpWebRequest.GetResponse()
*/
第二段
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://www.alibabacloud.com");
request.Timeout = 5000;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
request = (HttpWebRequest) WebRequest.Create("https://www.cnblogs.com");
request.Timeout = 1;
response = (HttpWebResponse) request.GetResponse();
//Exception
/*
Unhandled Exception: System.OperationCanceledException: The operation was canceled.
at System.Net.HttpWebRequest.GetResponse()
*/
初步估计的原因是,Http 请求中 Keep-Alive的关系,还有一个可能是 Timeout 的这个说明:
**The Timeout applies to the entire request and response, not individually to the GetRequestStream and GetResponse method calls. ** 然而具体的还没搞清楚,还需要去验证。
后记
其实,设置这两个属性你可能只需要找到文档,分分钟就可以搞定,但是我为什么会在这个过程遇到这些问题呢?一方面是对于C# 中网络请求的不熟悉,其次是找个时间,把以前的代码需要重构一下了,比如把HttpWebRequest
换成 HttpClient
等等。也让我加深了对Http协议
的理解。
Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by s...
方案一:
重启dubbo连接 zookeeper
方案二:
经压测,greys跟踪得知,是dubbo的monitor的问题。主要超时的方法是dubbo的getIP方法,monitor每次收集数据的时候都要根据域名获取zk的IP,这一步耗时很长。
public String getIp() {
if (ip == null) {
ip = NetUtils.getIpByHost(host);
}
return ip; }
现在改了dubbo的源码,monitor每次收集数据的时候不获取zk的ip,直接用域名。增加如下方法,
public String toServiceString(boolean useIP){
return buildString(true, false, useIP, true); }
修改AbstractMonitorFactory的方法
public Monitor getMonitor(URL url) {
url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
String key = url.toServiceString(false);
LOCK.lock();
try { Monitor monitor = MONITORS.get(key); if (monitor != null) { return monitor; } monitor = createMonitor(url); if (monitor == null) { throw new IllegalStateException("Can not create monitor " + url); } MONITORS.put(key, monitor); return monitor; } finally { // 释放锁 LOCK.unlock(); } }
关于Swarm mode中遇到的坑----join节点时,报错:Timeout和swarm节点什么意思的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...、android – java.net.SocketTimeoutException:timeout、C# .net 中 Timeout 的处理及遇到的问题、Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by s...等相关内容,可以在本站寻找。
本文标签: