我在Vert.x 3.7.0和3.7.1中有一个奇怪的问题:HttpRequest发送方法在请求正文中传输数据(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


Vert.x在3.7.0之前没有问题:我尝试了3.6.3,并且send()sendForm()都返回了java.net.ConnectException: Connection refused: no further information。这就是为什么我怀疑这是一个错误(在Vert.x中,或者在底层的io.netty中),除非我在代码中执行了未定义行为。

这里有来自Vert.x社区的人吗? :)

在此先感谢您的帮助。

附言我在Windows 10,使用JVM Amazon Corretto 11.0.3的Java上。

最佳答案

在Windows 10上,这一次发生在我身上。我禁用了防火墙,然后重新启动了Vert.x应用程序,这神奇起来。

关于java - Vert.x 3.7.0 HttpRequest sendForm()/sendBuffer()/sendJson()方法如果主机不可用则永远不会返回,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56793795/

10-12 04:49