use*_*136 1 sockets bind unix-socket netty grpc-java
我有以下代码,它将创建一个Java gRPC服务器并尝试将其绑定到USD / tmp / foo:
EpollEventLoopGroup group = new EpollEventLoopGroup();
Server server =
NettyServerBuilder.forAddress(new DomainSocketAddress("/tmp/foo"))
.channelType(EpollServerSocketChannel.class)
.bossEventLoopGroup(group)
.workerEventLoopGroup(group)
.addService(new Impl())
.build()
.start();
server.awaitTermination();
Run Code Online (Sandbox Code Playgroud)
但是,此操作失败bind(..) failed: Invalid argument:
Exception in thread "main" java.io.IOException: Failed to bind
at io.grpc.netty.NettyServer.start(NettyServer.java:231)
at io.grpc.internal.ServerImpl.start(ServerImpl.java:151)
at io.grpc.internal.ServerImpl.start(ServerImpl.java:75)
at com.google.devtools.javatools.jade.pkgloader.GrpcLocalServer.main(GrpcLocalServer.java:60)
Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Invalid argument
at io.netty.channel.unix.Errors.newIOException(Errors.java:117)
at io.netty.channel.unix.Socket.bind(Socket.java:291)
at io.netty.channel.epoll.AbstractEpollChannel.doBind(AbstractEpollChannel.java:714)
at io.netty.channel.epoll.EpollServerSocketChannel.doBind(EpollServerSocketChannel.java:70)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:364)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:309)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
我检查了该文件/tmp/foo是否不存在,是否对该文件及其父目录具有写权限,并且没有任何进程绑定到该文件(netstat -na | grep /tmp/foo.socket)。我在Linux系统上。
我是否缺少明显的东西?
使用EpollServerDomainSocketChannel而不是EpollServerSocketChannel解决问题。
为了将来轻松进行复制/粘贴,以下内容绑定(侦听)到UDS:
EpollEventLoopGroup group = new EpollEventLoopGroup();
Server server = NettyServerBuilder.forAddress(new DomainSocketAddress("/tmp/foo"))
.channelType(EpollServerDomainSocketChannel.class)
.workerEventLoopGroup(group)
.bossEventLoopGroup(group)
.addService(new Impl())
.build()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1079 次 |
| 最近记录: |