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

当群员列表缓存文件不完整时, 发生 MalformedInputException 导致 bot init 失败 #2399

Closed
zhaodice opened this issue Dec 20, 2022 · 4 comments
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:bug 类型: bug
Milestone

Comments

@zhaodice
Copy link
Contributor

问题描述

在登录时加载Group member缓存期间时出现的错误(但不确定是不是因为缓存原因)

复现

根据用户的反馈,在直接登录时加载群缓存时就复现了,目前还在调查是否和缓存有关,打算让用户删除缓存尝试

mirai-core 版本

2.13.2

bot-protocol

ANDROID_PHONE

其他组件版本

No response

系统日志

[17:42:43] [INFO] Starting mirai-console... 
[17:42:43] [INFO] 

==================================[ Mirai consosle 2.13.2 ]===================================
__ __ __ __ ______ __
| \ / \ \ | \/ \ | \
| ▓▓\ / ▓▓\▓▓ ______ ______ \▓▓ ▓▓▓▓▓▓\ ______ _______ _______ ______ | ▓▓ ______
| ▓▓▓\ / ▓▓▓ \/ \ | \| \ ▓▓ \▓▓/ \| \ / \/ \| ▓▓/ \
| ▓▓▓▓\ ▓▓▓▓ ▓▓ ▓▓▓▓▓▓\ \▓▓▓▓▓▓\ ▓▓ ▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\ ▓▓ ▓▓▓▓▓▓\
| ▓▓\▓▓ ▓▓ ▓▓ ▓▓ ▓▓ \▓▓/ ▓▓ ▓▓ ▓▓ __| ▓▓ | ▓▓ ▓▓ | ▓▓\▓▓ \| ▓▓ | ▓▓ ▓▓ ▓▓ ▓▓
| ▓▓ \▓▓▓| ▓▓ ▓▓ ▓▓ | ▓▓▓▓▓▓▓ ▓▓ ▓▓__/ \ ▓▓__/ ▓▓ ▓▓ | ▓▓_\▓▓▓▓▓▓\ ▓▓__/ ▓▓ ▓▓ ▓▓▓▓▓▓▓▓
| ▓▓ \▓ | ▓▓ ▓▓ ▓▓ \▓▓ ▓▓ ▓▓\▓▓ ▓▓\▓▓ ▓▓ ▓▓ | ▓▓ ▓▓\▓▓ ▓▓ ▓▓\▓▓ \
\▓▓ \▓▓\▓▓\▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓\▓▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓▓▓▓▓▓

[17:42:44] [INFO] Loaded account secrets from local cache. 
[17:42:44] [INFO] ECDH key is valid. 
[17:42:44] [INFO] Saved account secrets to local cache for fast login. 
[17:42:44] [INFO] Login successful. 
[17:42:44] [INFO] Server time updated, serverTime: 1671529365, diff: 1ms=0.001s 
[17:42:44] [INFO] Syncing friend message history... 
[17:42:44] [INFO] Loaded 111 friends from local cache. 
[17:42:44] [INFO] Start loading stranger list... 
[17:42:44] [INFO] Start loading friendGroup list... 
[17:42:44] [INFO] Start loading group list... 
[17:42:44] [INFO] Successfully loaded stranger list: 0 in total 
[17:42:44] [INFO] Online OtherClients: MOA-AL00(MOBILE) 
[17:42:44] [INFO] Successfully loaded friendGroup list: 14 in total 
[17:42:44] [INFO] Loaded 3 members from local cache for group ................
................................
[17:42:45] [WARNING] Network selector received exception, closing bot. (kotlinx.coroutines.JobCancellationException: Parent job is Cancelling; job=z{Cancelling}@aa95aa0) 
[17:42:45] [ERROR] Exception in coroutine 'unnamed' 
[17:42:45] [ERROR] net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.MalformedInputException: Input length = 1
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.CharsetJVMKt.throwExceptionWrapped(Unknown Source:15)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.EncodingKt.net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.CharsetJVMKt.decode(SourceFile:112)
                                                                       decode
	at net.mamoe.mirai.utils.MiraiUtils__IOKt.net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.EncodingKt.decode$default(Unknown Source:9)
                                           readAllText
	at net.mamoe.mirai.utils.MiraiUtils.readAllText(Unknown Source:0)
	at net.mamoe.mirai.utils.FileKt.readText(Unknown Source:8)
	at net.mamoe.mirai.internal.network.GroupMemberListCaches.a(SourceFile:29)
	at net.mamoe.mirai.internal.network.components.ContactUpdaterImpl.net.mamoe.mirai.internal.network.components.ContactUpdaterImpl.addGroupToBot(SourceFile:102)
                                                                   access$addGroupToBot
	at net.mamoe.mirai.internal.network.components.ContactUpdaterImpl$reloadGroupList$2$2$1$1.invokeSuspend(SourceFile:177)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:5)
	at kotlinx.coroutines.DispatchedTask.run(Unknown Source:109)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(SourceFile:85)
                                                            kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask
                                                            kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker
                                                            run

[17:42:45] [INFO] Loaded 791 members from local cache for group ..............
........................
[17:42:46] [WARNING] An exception was thrown during 'loading groups' of Bot 3103132950. Trying to ignore the error and continue logging in... 
[17:42:46] [ERROR] Exception in coroutine 'BotInitProcessor.init' 
[17:42:46] [ERROR] java.lang.IllegalStateException: Exception in attached Job 'BotInitProcessor.init'
	at net.mamoe.mirai.internal.network.handler.state.JobAttachStateObserver$stateChanged0$1.invokeSuspend(SourceFile:74)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:5)
	at kotlinx.coroutines.DispatchedTask.run(Unknown Source:109)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(SourceFile:85)
                                                            kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask
                                                            kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker
                                                            run
Caused by: net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.MalformedInputException: Input length = 1
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.CharsetJVMKt.throwExceptionWrapped(Unknown Source:15)
	at net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.EncodingKt.net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.CharsetJVMKt.decode(SourceFile:112)
                                                                       decode
	at net.mamoe.mirai.utils.MiraiUtils__IOKt.net.mamoe.mirai.internal.deps.io.ktor.utils.io.charsets.EncodingKt.decode$default(Unknown Source:9)
                                           readAllText
	at net.mamoe.mirai.utils.MiraiUtils.readAllText(Unknown Source:0)
	at net.mamoe.mirai.utils.FileKt.readText(Unknown Source:8)
	at net.mamoe.mirai.internal.network.GroupMemberListCaches.a(SourceFile:29)
	at net.mamoe.mirai.internal.network.components.ContactUpdaterImpl.net.mamoe.mirai.internal.network.components.ContactUpdaterImpl.addGroupToBot(SourceFile:102)
                                                                   access$addGroupToBot
	at net.mamoe.mirai.internal.network.components.ContactUpdaterImpl$reloadGroupList$2$2$1$1.invokeSuspend(SourceFile:177)
	... 3 more
	Suppressed: net.mamoe.mirai.utils.StacktraceException: Unwrapped exception: StateSwitchingException(old=StateLoading, new=StateClosed, cause=kotlinx.coroutines.JobCancellationException: Parent job is Cancelling; job=z{Cancelled}@aa95aa0)
[17:42:46] [INFO] Bot login successful. 
[17:42:46] [INFO] Bot cancelled: Bot closed 
[17:42:46] [INFO] ->>Login Operation finished.<<-

网络日志

No response

补充信息

原始信息已被混淆,这是使用mapping.txt 解混淆的结果,可能有出入。

@zhaodice
Copy link
Contributor Author

我无法在不混淆的情况下复现错误,因为我的安卓死丢丢有BUG,只要proguard为false,就告诉我找不到$j类,很神奇

@zhaodice
Copy link
Contributor Author

需要更多的信息可以继续提供

@Him188
Copy link
Member

Him188 commented Dec 20, 2022

这还是大概率是你的混淆或者优化问题,改变了代码逻辑

@zhaodice
Copy link
Contributor Author

zhaodice commented Dec 20, 2022

这还是大概率是你的混淆或者优化问题,改变了代码逻辑

倒也不一定,因为我发现只有这一个用户有这个问题,其他人都是稳定运行的,而且我查阅到崩溃有关发生在

    operator fun get(id: Long): GroupMemberListCache {
        return map.getOrPut(id) {
            val file = resolveCacheFile(id)
            if (file.exists() && file.isFile) {
                val text = file.readText()
                if (text.isNotBlank()) {
                    return JsonForCache.decodeFromString(GroupMemberListCache.serializer(), text)
                }
            }

            GroupMemberListCache(0, emptyList())
        }
    }

readText发生的错误,而通过查阅资料MalformedInputException: Input length = 1得知,这很可能是文件编码问题(极有可能所写入文件一半被安卓系统意外杀死导致文件损坏),但我并不确定,也许可以加个容错机制。
特别的,我要求用户自行删除了缓存文件,问题消失了

@Him188 Him188 added t:bug 类型: bug M 优先级: 主要 s:core 子系统: mirai-core labels Jan 2, 2023
@Him188 Him188 modified the milestones: 2.13.3, 2.14.0-RC Jan 2, 2023
@Him188 Him188 changed the title Android 10 出现 MalformedInputException: Input length = 1 当群员列表缓存文件不完整时, 发生 MalformedInputException 导致 bot init 失败 Jan 2, 2023
@Him188 Him188 closed this as completed in eea2ef5 Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:bug 类型: bug
Projects
None yet
Development

No branches or pull requests

2 participants