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

KookBC 在被 Linux nohup 命令包装时无法工作 #30

Closed
SNWCreations opened this issue Apr 4, 2023 · 6 comments
Closed

KookBC 在被 Linux nohup 命令包装时无法工作 #30

SNWCreations opened this issue Apr 4, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@SNWCreations
Copy link
Owner

它原本由社区成员 Lonely#6788 提交。

您期望得到什么

KookBC 在无控制台模式下正常工作。

实际得到什么

KBCClient#loop 方法出现被依赖库忽略的报错,然后程序自动调用 shutdown 后结束。

重现错误的步骤

  1. 使用 Linux nohup 命令运行 KookBC (格式: nohup java -jar kookbc.jar &)
  2. 异常复现,日志会出现在当前路径的 nohup.out 文件

报错日志

[20:37:14] [Main Thread/ERROR]: Failed to read console input
java.io.IOException: Bad file descriptor
	at java.io.FileInputStream.readBytes(Native Method) ~[?:?]
	at java.io.FileInputStream.read(FileInputStream.java:276) ~[?:?]
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:282) ~[?:?]
	at java.io.BufferedInputStream.read(BufferedInputStream.java:343) ~[?:?]
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:270) ~[?:?]
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:313) ~[?:?]
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188) ~[?:?]
	at java.io.InputStreamReader.read(InputStreamReader.java:177) ~[?:?]
	at java.io.BufferedReader.fill(BufferedReader.java:162) ~[?:?]
	at java.io.BufferedReader.readLine(BufferedReader.java:329) ~[?:?]
	at java.io.BufferedReader.readLine(BufferedReader.java:396) ~[?:?]
	at net.minecrell.terminalconsole.SimpleTerminalConsole.readCommands(SimpleTerminalConsole.java:180) ~[k.jar:0.26.13]
	at net.minecrell.terminalconsole.SimpleTerminalConsole.start(SimpleTerminalConsole.java:143) ~[k.jar:0.26.13]
	at snw.kookbc.impl.KBCClient.loop(KBCClient.java:277) ~[k.jar:0.26.13]
	at snw.kookbc.Main.main1(Main.java:163) ~[k.jar:0.26.13]
	at snw.kookbc.Main.main0(Main.java:125) ~[k.jar:0.26.13]
	at snw.kookbc.Main.main(Main.java:44) ~[k.jar:0.26.13]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
	at snw.kookbc.LaunchMain.lambda$launch$1(LaunchMain.java:176) ~[k.jar:0.26.13]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]

相关信息

  • KookBC 版本: 0.26.13
  • JKook API 版本: 0.48.2
  • 您使用的 JKook 插件 的相关信息 (如 名称、作者、版本): 无
  • Java 版本: 17
  • 操作系统 (及其版本): Linux 4.18 amd64 (由 CODING 的 Cloud Studio 提供)
@SNWCreations SNWCreations added the bug Something isn't working label Apr 4, 2023
@SNWCreations SNWCreations self-assigned this Apr 4, 2023
@SNWCreations
Copy link
Owner Author

SNWCreations commented Apr 5, 2023

在尝试了如下方案后,我决定从依赖库 TerminalConsoleAppender 下手,移除其 start 方法的 try catch ,转为由我自己处理。

  1. 尝试直接检查 FileDescriptor.in.valid() -> 失败,总是 true
  2. 尝试通过反射获取 System.in 背后的 FileDescriptor ,检查其 valid() 返回值 -> 失败,总是 true

以上方案均在 nohup 包装下实验,用单独的 Java 文件编写对应代码。

@SNWCreations
Copy link
Owner Author

@xiaoACE6716 提供的资料: mamoe/mirai-console#229
同样与 Linux nohup 有关,但其最后提供的方法治标不治本。

@SNWCreations
Copy link
Owner Author

更改修补方案: 不再 fork TCA ,改为提供一个类似 Condition 的对象用于挂起线程。

SNWCreations added a commit that referenced this issue Apr 6, 2023
@SNWCreations SNWCreations mentioned this issue Apr 6, 2023
@SNWCreations
Copy link
Owner Author

进一步修补方案: 使用检查当前目录是否存在一个名为 KOOKBC_STOP 的文件的方式判断是否应该关闭程序。

SNWCreations added a commit that referenced this issue Apr 8, 2023
This commit has fixed issue #30.
This commit added a special way for users who uses "nohup" command to run KookBC to stop the client instance.
See the log in the working directory, you will know.
(It is easy, write a file named KOOKBC_STOP to the working
directory, KookBC will found it and stop itself.)

------
Tested-by: ZX夏夜之风 <snwcreations@qq.com>
@SNWCreations
Copy link
Owner Author

#32 修补不彻底。此 Issue 暂时不能关闭。
恢复原有方案: 使用 fork 的 TCA ,自行抓取异常。

SNWCreations added a commit that referenced this issue Apr 8, 2023
This reverts commit c9a9093.
SNWCreations added a commit that referenced this issue Apr 8, 2023
This reverts commit c9a9093.
SNWCreations added a commit that referenced this issue Apr 8, 2023
SNWCreations added a commit that referenced this issue Apr 8, 2023
SNWCreations added a commit that referenced this issue Apr 8, 2023
@SNWCreations SNWCreations mentioned this issue Apr 8, 2023
SNWCreations added a commit that referenced this issue Apr 8, 2023
@SNWCreations
Copy link
Owner Author

完全修复。

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

No branches or pull requests

1 participant