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

replace NettyChannelBuilder.nameResolverFactory #7557

Closed
usertree opened this issue Oct 27, 2020 · 6 comments
Closed

replace NettyChannelBuilder.nameResolverFactory #7557

usertree opened this issue Oct 27, 2020 · 6 comments

Comments

@usertree
Copy link

Grpc load balancing needs to be used, but the method nameResolverFactory() has been abandoned. How to replace it?
image

@voidzcy
Copy link
Contributor

voidzcy commented Oct 27, 2020

As the Javadoc says, if you are implementing your own resolver, you'd implement a provider for it. Then you'd either need to register your provider to the global registry, either with SPI mechanism or do it manually. Then you do not need to provide the name resolver factory to the channel builder, the channel can select it automatically from the registry.

@voidzcy
Copy link
Contributor

voidzcy commented Oct 27, 2020

#7133 is the issue for encouraging migrating away from NameResolver.Factory related APIs.

@usertree
Copy link
Author

usertree commented Oct 28, 2020

@voidzcy I tried to add resolver and provider,but a new error was reported

Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE: io exception\nChannel Pipeline: [SslHandler#0, ProtocolNegotiators$ClientTlsHandler#0, WriteBufferingAndExceptionHandler#0, DefaultChannelPipeline$TailContext#0]
        at io.grpc.Status.asRuntimeException(Status.java:533)
        at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:533)
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:616)
        at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:69)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:802)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:781)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
        ... 3 more
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
        at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1566)
        at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:545)
        at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1217)
        at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1185)
        at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:511)
        at io.netty.handler.ssl.JdkSslEngine.wrap(JdkSslEngine.java:82)
        at io.netty.handler.ssl.JdkAlpnSslEngine.wrap(JdkAlpnSslEngine.java:133)
        at io.netty.handler.ssl.SslHandler.wrap(SslHandler.java:1079)
        at io.netty.handler.ssl.SslHandler.wrapNonAppData(SslHandler.java:970)
        at io.netty.handler.ssl.SslHandler.access$1800(SslHandler.java:167)
        at io.netty.handler.ssl.SslHandler$SslTasksRunner.resumeOnEventExecutor(SslHandler.java:1706)
        at io.netty.handler.ssl.SslHandler$SslTasksRunner.access$2000(SslHandler.java:1586)
        at io.netty.handler.ssl.SslHandler$SslTasksRunner$1.run(SslHandler.java:1746)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        ... 1 more
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:198)
        at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1729)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:333)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:325)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1688)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:226)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1082)
        at sun.security.ssl.Handshaker$1.run(Handshaker.java:1015)
        at sun.security.ssl.Handshaker$1.run(Handshaker.java:1012)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1504)
        at io.netty.handler.ssl.SslHandler.runAllDelegatedTasks(SslHandler.java:1550)
        at io.netty.handler.ssl.SslHandler.access$1900(SslHandler.java:167)
        at io.netty.handler.ssl.SslHandler$SslTasksRunner.run(SslHandler.java:1737)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        ... 1 more
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching etcd found.
        at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:215)
        at sun.security.util.HostnameChecker.match(HostnameChecker.java:97)
        at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:462)
        at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:442)
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:261)
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:144)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1675)
        ... 12 more

@voidzcy
Copy link
Contributor

voidzcy commented Oct 28, 2020

I saw Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching etcd found.. It looks you are probably running on test environment (as your hostname is etcd). You can use ManagedChannelBuilder.overrideAuthority(...) to override the hostname used for TLS hostname verification to match the hostname in your test cert.

@ejona86
Copy link
Member

ejona86 commented Oct 29, 2020

@usertree, it seems you are trying to override the DNS name resolver with your own. Make sure to return a value larger than 5 from your provider's priority() method. I'd suggest a value of 7.

@usertree
Copy link
Author

@voidzcy @ejona86 Thank you. The problem is solved

@ejona86 ejona86 closed this as completed Nov 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants