我对Vert.x 3.7.0和3.7.1有一个奇怪的问题:HttpRequest
发送方法可以在请求正文中传输数据(sendForm()
,sendJson()
,{{1 }}等-如果主机不可用,除sendBuffer()
)之外的所有内容都将永远不会返回。
如果端口4012上没有服务器,则以下代码将永不返回:
send()
如果我改用 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 -> {...})
3.7.0之前的Vert.x没有问题:我尝试了3.6.3,并且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
和send()
都返回了sendForm()
。这就是为什么我怀疑这是一个错误(在Vert.x或底层io.netty中),除非我在代码中执行了未定义行为。
这里有Vert.x社区的人吗? :)
在此先感谢您的帮助。
P.S。我在Windows 10,使用JVM Amazon Corretto 11.0.3的Java。
答案 0 :(得分:0)
在Windows 10上,这一次发生在我身上。我禁用了防火墙,然后重新启动了Vert.x应用程序,这真是不可思议。