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

GroupChannelOptionForLinux初始化时EventLoopGroup需增加动态判断 #375

Closed
sakimonk opened this issue Sep 28, 2024 · 2 comments
Closed
Assignees
Labels
enhancement;功能增强 Function enhancement;功能增强

Comments

@sakimonk
Copy link

sakimonk commented Sep 28, 2024

你的问题 | 使用场景

在安卓手机中运行 ioGame 报错" no netty_transport_native_epoll in java.library.path", 研究后发现轻量级或嵌入式 Linux 发行版可能没有完整的 I/O 多路复用支持,如 epoll,同时代码写死EpollEventLoopGroup判断导致报错。
修复建议:
修改GroupChannelOptionForLinux类增加动态判断,系统不支持epoll时切换成nio,可以参考com.alipay.remoting.util.NettyEventLoopUtil代码实现

预期值

安卓手机中运行没有报错

实际值

在安卓手机中运行iogame报错" no netty_transport_native_epoll in java.library.path"

复现步骤

安卓手机中运行 ioGame 报如下错误

Exception in thread "InternalRunOne2" java.lang.UnsatisfiedLinkError: failed to load the required native library
        at io.netty.channel.epoll.Epoll.ensureAvailability(Epoll.java:81)
        at io.netty.channel.epoll.EpollEventLoop.<clinit>(EpollEventLoop.java:57)
        at io.netty.channel.epoll.EpollEventLoopGroup.newChild(EpollEventLoopGroup.java:189)
        at io.netty.channel.epoll.EpollEventLoopGroup.newChild(EpollEventLoopGroup.java:37)
        at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
        at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:60)
        at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:49)
        at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:59)
        at io.netty.channel.epoll.EpollEventLoopGroup.<init>(EpollEventLoopGroup.java:117)
        at io.netty.channel.epoll.EpollEventLoopGroup.<init>(EpollEventLoopGroup.java:104)
        at io.netty.channel.epoll.EpollEventLoopGroup.<init>(EpollEventLoopGroup.java:81)
        at com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForLinux.bossGroup(GroupChannelOptionForLinux.java:39)
        at com.iohao.game.external.core.netty.micro.SocketMicroBootstrap.startup(SocketMicroBootstrap.java:52)
        at com.iohao.game.external.core.netty.DefaultExternalServer.startup(DefaultExternalServer.java:86)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.UnsatisfiedLinkError: /data/data/com.termux/files/usr/tmp/libnetty_transport_native_epoll_aarch_643820611535310915400.so: dlopen failed: library "libdl.so.2" not found: needed by /data/data/com.termux/files/usr/tmp/libnetty_transport_native_epoll_aarch_643820611535310915400.so in namespace (default)
        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
        at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:384)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:228)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:170)
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
        at java.base/java.lang.Runtime.load0(Runtime.java:751)
        at java.base/java.lang.System.load(System.java:1912)
        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:36)
        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:396)
        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:218)
        at io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:334)
        at io.netty.channel.epoll.Native.<clinit>(Native.java:96)
        at io.netty.channel.epoll.Epoll.<clinit>(Epoll.java:40)
        ... 16 more
        Suppressed: java.lang.UnsatisfiedLinkError: /data/data/com.termux/files/usr/tmp/libnetty_transport_native_epoll_aarch_643820611535310915400.so: dlopen failed: library "libdl.so.2" not found: needed by /data/data/com.termux/files/usr/tmp/libnetty_transport_native_epoll_aarch_643820611535310915400.so in namespace (default)
                at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
                at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:384)
                at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:228)
                at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:170)
                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
                at java.base/java.lang.Runtime.load0(Runtime.java:751)
                at java.base/java.lang.System.load(System.java:1912)
                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:36)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:430)
                at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:422)
                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:388)
                ... 20 more
        Suppressed: java.lang.UnsatisfiedLinkError: no netty_transport_native_epoll_aarch_64 in java.library.path: /usr/java/packages/lib:/lib:/usr/lib
                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:814)
                at java.base/java.lang.System.loadLibrary(System.java:1948)
                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:396)
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                ... 19 more
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_transport_native_epoll_aarch_64 in java.library.path: /usr/java/packages/lib:/lib:/usr/lib
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:814)
                        at java.base/java.lang.System.loadLibrary(System.java:1948)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                        at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:430)
                        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:422)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:388)
                        ... 20 more
        Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_transport_native_epoll
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
                at io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:337)
                ... 18 more
        Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_transport_native_epoll.so
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186)
                ... 19 more
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_transport_native_epoll in java.library.path: /usr/java/packages/lib:/lib:/usr/lib
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:814)
                        at java.base/java.lang.System.loadLibrary(System.java:1948)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:396)
                        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                        ... 19 more
                        Suppressed: java.lang.UnsatisfiedLinkError: no netty_transport_native_epoll in java.library.path: /usr/java/packages/lib:/lib:/usr/lib
                                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:814)
                                at java.base/java.lang.System.loadLibrary(System.java:1948)
                                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                                at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:430)
                                at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:422)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:388)
                                ... 20 more

版本

  • ioGame version:
    ioGame17分支代码
@iohao iohao self-assigned this Sep 28, 2024
@iohao iohao added the enhancement;功能增强 Function enhancement;功能增强 label Sep 28, 2024
@iohao
Copy link
Owner

iohao commented Sep 28, 2024

好的。

iohao added a commit that referenced this issue Sep 28, 2024
@iohao
Copy link
Owner

iohao commented Sep 28, 2024

default value

public GroupChannelOption getGroupChannelOption() {
if (Objects.isNull(this.groupChannelOption)) {
this.groupChannelOption = createGroupChannelOption();
}
return this.groupChannelOption;
}
private GroupChannelOption createGroupChannelOption() {
if (OsInfo.isMac()) {
return new GroupChannelOptionForMac();
}
// #375,Lightweight or embedded Linux distributions may not have fulled I/O multiplexing support
if (OsInfo.isLinux() && Epoll.isAvailable()) {
return new GroupChannelOptionForLinux();
}
// other system nio
return new GroupChannelOptionForOther();
}

set GroupChannelOption

private ExternalServer createExternalServer(int port) {    
    var builder = DefaultExternalServer.newBuilder(port);
    // ExternalCore setting
    var setting = builder.setting();
    // set GroupChannelOption
    setting.setGroupChannelOption(new GroupChannelOptionForOther());
}

@iohao iohao closed this as completed Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement;功能增强 Function enhancement;功能增强
Projects
None yet
Development

No branches or pull requests

2 participants