java - 如果主机不可用,Vert.x 3.7.0 HttpRequest sendForm()/sendBuffer()/sendJson() 方法永远不会返回
问题描述
Vert.x 3.7.0 和 3.7.1 有一个奇怪的问题:如果主机不可用,在HttpRequest
请求正文中传输数据的 send 方法(sendForm()
,等 - 所有除了)永远不会返回。sendJson()
sendBuffer()
send()
如果端口 4012 上没有服务器,则以下代码永远不会返回:
HttpClientOptions options = new HttpClientOptions()
.setDefaultHost("localhost")
.setDefaultPort(4012);
Vertx vertx = Vertx.vertx();
WebClient webClient = WebClient.create(vertx, new WebClientOptions(options));
HttpRequest<Buffer> request = webClient.request(HttpMethod.POST, "/test");
logger.info("Sending request as sendForm()");
request.sendForm(MultiMap.caseInsensitiveMultiMap(), event -> {
if (event.failed()) {
logger.error("Failed!", event.cause());
} else {
logger.info("Succeeded! Code {} {}", event.result().statusCode(), event.result().statusMessage());
}
vertx.close();
});
如果我request.send(event -> {...})
改用,那么它会打印(如预期的那样):
27.06.19 16:47:17,352 ERROR - Failed! io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:4012
at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:632)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.ConnectException: Connection refused: no further information
... 11 more
3.7.0 之前的 Vert.x 没有问题:我尝试了 3.6.3,并且send()
都sendForm()
使用java.net.ConnectException: Connection refused: no further information
. 这就是为什么我怀疑这是一个错误(在 Vert.x 中,或者可能在底层 io.netty 中),除非我在我的代码中做一些未定义行为的事情。
这里有来自 Vert.x 社区的人吗?:)
提前感谢您的帮助。
PS 我在 Windows 10 上,Java 使用 JVM Amazon Corretto 11.0.3。
解决方案
我曾经在 Windows 10 上遇到过这种情况。我禁用了防火墙,然后重新启动了 Vert.x 应用程序,这就是魔法。
推荐阅读
- python - 我的代码正在执行第一部分而不是第二部分。两个部分都可以自己正常工作
- c++ - 使用其基类重新创建对象是否定义良好?
- c# - ActiveX 旧版应用程序 IE11 生命周期结束
- python - 根据条件动态地将数据帧拆分为多个数据帧
- sql-server - 在 Ubuntu 20.10 机器上使用 pyodbc 连接到 Microsoft SQL Server Express 的问题
- c# - 我的协程在'yield return new WaitForSeconds(.01f)' 后停止
- javascript - DiscordAPIError:404:未找到
- c - CS50 pset5 Speller - :( 程序没有内存错误 valgrind 测试失败;有关更多信息,请参阅日志
- r - 使用 ggplot 在条形图中绘制连续变量与分类变量
- ssl - 从 certificate.pem 中提取公钥