Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpClient#doOnConnected invalid #5522

Open
1 task done
wormsStorm opened this issue Mar 28, 2024 · 1 comment
Open
1 task done

httpClient#doOnConnected invalid #5522

wormsStorm opened this issue Mar 28, 2024 · 1 comment
Labels
type: bug Something isn't working

Comments

@wormsStorm
Copy link

wormsStorm commented Mar 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

@Override
protected HttpClient createInstance() {
    // configure pool resources.
    HttpClientProperties.Pool pool = properties.getPool();
    ConnectionProvider connectionProvider = buildConnectionProvider(pool);
    HttpClient httpClient = HttpClient.create(connectionProvider)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, properties.getConnectTimeout());
    if (serverProperties.getHttp2().isEnabled()) {
        httpClient = httpClient.protocol(HttpProtocol.HTTP11, HttpProtocol.H2);
    }
    HttpClientProperties.Proxy proxy = properties.getProxy();
    if (StringUtils.isNotEmpty(proxy.getHost())) {
        httpClient = setHttpClientProxy(httpClient, proxy);
    }
    httpClient.doOnConnected(connection -> {
        connection.addHandlerLast(new IdleStateHandler(properties.getReaderIdleTime(), properties.getWriterIdleTime(), properties.getAllIdleTime(), TimeUnit.MILLISECONDS));
        connection.addHandlerLast(new WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
        connection.addHandlerLast(new ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
    });
    if (Objects.nonNull(loopResources)) {
        httpClient.runOn(loopResources);
    }
    HttpClientProperties.Ssl ssl = properties.getSsl();
    if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
            || ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
            || ssl.isUseInsecureTrustManager()) {
        httpClient = httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
    }
    if (properties.isWiretap()) {
        httpClient = httpClient.wiretap(true);
    }
    // set to false, fix java.io.IOException: Connection reset by peer
    // see https://github.com/reactor/reactor-netty/issues/388
    return httpClient.keepAlive(properties.isKeepAlive());
}

Expected Behavior

@Override
protected HttpClient createInstance() {
    // configure pool resources.
    HttpClientProperties.Pool pool = properties.getPool();
    ConnectionProvider connectionProvider = buildConnectionProvider(pool);
    HttpClient httpClient = HttpClient.create(connectionProvider)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, properties.getConnectTimeout());
    if (serverProperties.getHttp2().isEnabled()) {
        httpClient = httpClient.protocol(HttpProtocol.HTTP11, HttpProtocol.H2);
    }
    HttpClientProperties.Proxy proxy = properties.getProxy();
    if (StringUtils.isNotEmpty(proxy.getHost())) {
        httpClient = setHttpClientProxy(httpClient, proxy);
    }
   // The httpClient needs to be reassigned
   // The httpClient needs to be reassigned
   // The httpClient needs to be reassigned
    httpClient = httpClient.doOnConnected(connection -> {
        connection.addHandlerLast(new IdleStateHandler(properties.getReaderIdleTime(), properties.getWriterIdleTime(), properties.getAllIdleTime(), TimeUnit.MILLISECONDS));
        connection.addHandlerLast(new WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
        connection.addHandlerLast(new ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
    });
    if (Objects.nonNull(loopResources)) {
       // The httpClient needs to be reassigned
       // The httpClient needs to be reassigned
       // The httpClient needs to be reassigned
        httpClient = httpClient.runOn(loopResources);
    }
    HttpClientProperties.Ssl ssl = properties.getSsl();
    if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
            || ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
            || ssl.isUseInsecureTrustManager()) {
        httpClient = httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
    }
    if (properties.isWiretap()) {
        httpClient = httpClient.wiretap(true);
    }
    // set to false, fix java.io.IOException: Connection reset by peer
    // see https://github.com/reactor/reactor-netty/issues/388
    return httpClient.keepAlive(properties.isKeepAlive());
}

Steps To Reproduce

no

Environment

ShenYu version(s):2.6.1

Debug logs

no

Anything else?

no

@wormsStorm wormsStorm added the type: bug Something isn't working label Mar 28, 2024
@Aias00
Copy link
Contributor

Aias00 commented Apr 13, 2024

could u pls describe what the change for ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants