简体   繁体   English

使用SSL和Postman的java.nio.channels.ClosedChannelException

[英]java.nio.channels.ClosedChannelException with SSL and Postman

I have a complete minimum working example of a vertx server that will throw a ClosedChannelException if a request is made to it via Postman. 我有一个vertx服务器的完整最小工作示例,如果通过Postman向它发出请求,它将抛出ClosedChannelException From the point of view of postman, the request doesn't appear to have failed- the response is received as expected. 从邮递员的角度来看,请求似乎没有失败 - 按预期收到回复。 It's only the vertx server that is throwing this error. 它只是vertx服务器抛出此错误。

It is only happening once per new connection. 每个新连接只发生一次。 Consecutive calls through postman won't trigger this error, but quitting postman entirely and making a call again will. 通过邮递员的连续电话不会触发此错误,但完全退出邮递员并再次拨打电话将会。 It also will only happen if SSL is used. 它也只会在使用SSL时发生。 If the lines that enable ssl are removed, this error is not thrown. 如果删除了启用ssl的行,则不会抛出此错误。

If a request is made by a method other than postman (browser/fetch), no exception is thrown. 如果请求是由邮递员以外的方法(浏览器/提取)发出的,则不会引发异常。 Because I can only reproduce with Postman I might not be bothered by this, but I am seeing this same error appear multiple times per second in my non-local dev environment on AWS. 因为我只能用Postman重现,所以我可能不会对此感到困扰,但我发现在AWS的非本地开发环境中每秒多次出现同样的错误。 I don't know for sure what the source of those requests are because the exception doesn't contain that information, but my assumption is that those are elasticbeanstalk health checks. 我不确定这些请求的来源是什么,因为异常不包含该信息,但我的假设是那些是弹性豆秆健康检查。

Sample- 样品-

package com.acme.server;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.http.*;
import io.vertx.core.net.*;
import io.vertx.ext.web.Router;

class Main {
    public static void main(String args[]) {
        // Configure Vertx

        Vertx vertx = Vertx.vertx();

        // Configure HttpServer

        HttpServerOptions httpServerOptions = new HttpServerOptions();

        SelfSignedCertificate selfSignedCertificate = SelfSignedCertificate.create();

        // Comment out these lines and try `http` request. No exceptions thrown
        httpServerOptions.setKeyCertOptions(selfSignedCertificate.keyCertOptions());
        httpServerOptions.setSsl(true);
        ///////////////////////////////////////////////////////////////////////

        httpServerOptions.setPort(4443);

        HttpServer httpServer = vertx.createHttpServer(httpServerOptions);

        // Configure Router

        Router router = Router.router(vertx);
        router.route("/*").handler(routingContext -> {
            System.out.println("Requested route " + routingContext.normalisedPath());

            routingContext.response()
                    .setStatusCode(204)
                    .end();
        });
        httpServer.requestHandler(router);

        // Deploy Verticle

        vertx.deployVerticle(new MyVerticle());

        // Listen for java.nio.channels.ClosedChannelException

        httpServer.exceptionHandler((exception) -> {
            exception.printStackTrace();
        });

        // Start server

        System.out.println("Listening...");

        httpServer.listen();
    }

}

class MyVerticle extends AbstractVerticle {

    @Override
    public void start(Future<Void> startFuture) {
        startFuture.complete();
    }

}

Sample output- 样品输出 -

Listening... java.nio.channels.ClosedChannelException at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source) Requested route /dddd Requested route /dddd java.nio.channels.ClosedChannelException at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source) Requested route /dddd 听力... java.nio.channels.ClosedChannelException at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source)Requested route / dddd io请求的路由/ dddd java.nio.channels.ClosedChannelException。 netty.handler.ssl.SslHandler.channelInactive(...)(未知来源)请求的路由/ dddd

I think it might be because of any session information postman caches. 我认为可能是因为任何会话信息邮递员缓存。 Once you close the postman, may be the connection is closed by vertex, once you restart postman the request goes with some cached header values? 一旦你关闭邮递员,可能是连接被顶点关闭,一旦你重新启动邮递员,请求会带有一些缓存的标题值? Those session information will be not valid for your server. 这些会话信息对您的服务器无效。 So server starts fresh connection and response is OK. 所以服务器启动新连接并且响应正常。 Disable the caching settings of postman and then it might not occur. 禁用邮递员的缓存设置,然后可能不会发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.nio.channels.ClosedChannelException - java.nio.channels.ClosedChannelException java.nio.channels.ClosedChannelException-客户端关闭SSL - java.nio.channels.ClosedChannelException -Client shuts down SSL java.nio.channels.ClosedChannelException HTTP/2 与码头 - java.nio.channels.ClosedChannelException HTTP/2 with jetty 异常-java.nio.channels.ClosedChannelException - exception - java.nio.channels.ClosedChannelException jenkins主连接失败,出现java.nio.channels.ClosedChannelException - jenkins master connection fails with java.nio.channels.ClosedChannelException Stardog Connection.commit()引发java.nio.channels.ClosedChannelException - Stardog Connection.commit() raising java.nio.channels.ClosedChannelException GATLING Rest API 测试 - java.nio.channels.ClosedChannelException: Z3099A62586648C1 - GATLING Rest API testing - java.nio.channels.ClosedChannelException: null Apache Kafka:无法更新Metadata / java.nio.channels.ClosedChannelException - Apache Kafka: Failed to Update Metadata/java.nio.channels.ClosedChannelException 在Play应用程序中获取java.nio.channels.ClosedChannelException异常 - Getting java.nio.channels.ClosedChannelException excetion in Play Application 写入客户端通道时出现异常java.nio.channels.ClosedChannelException - Exception java.nio.channels.ClosedChannelException when write to client channel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM