mamoe / mirai

高效率 QQ 机器人支持库
https://mirai.mamoe.net
GNU Affero General Public License v3.0
14.36k stars 2.53k forks source link

MockTest 下 randomImage 偶尔会抛出 SIGSGEV #2768

Open Nambers opened 1 year ago

Nambers commented 1 year ago

问题描述

MockTest 下

internal fun randomImage(): BufferedImage {
    val width = (500..800).random()
    val height = (500..800).random()
    val image = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
    val graphics = image.createGraphics()
    for (x in 0 until width) {
        for (y in 0 until height) {
            graphics.color = Color(
                (0..0xFFFFFF).random()
            )
            graphics.drawRect(x, y, 1, 1)
        }
    }
    graphics.dispose()
    return image
}

graphics.dispose() 在一些情况下会抛出 SIGSGEV randomImage() 的 caller 是 MockNormalMember.avatarUrl 因为他第一次调用的时候会创建一个头像:

var avatarUrl: String by lateinitMutableProperty {
        runBlocking { MockImage.randomForPerson(declaredBot, id).getUrl(declaredBot) }
    }

我暂时还没找到稳定复现的方法和这个的诱因, 可能和我其他协程跑的东西有关。 先在这留个 issue, 后面有时间继续看看

Workaround: 在创建 MockNormalMember 后还没开始跑其他任务(或开始测试)时调用 member.avatarUrl() 给他头像初始化

复现

第一次调用 member.avatarUrl()

mirai-core 版本

2.15.0

bot-protocol

ANDROID_PHONE

其他组件版本

No response

系统日志

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5d59edfa85, pid=24028, tid=24037
#
# JRE version: OpenJDK Runtime Environment (17.0.8+7) (build 17.0.8+7)
# Java VM: OpenJDK 64-Bit Server VM (17.0.8+7, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x6dfa85]
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/eritque0arcus/github/MiraiCP/kotlin/shared/core.24028)
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#

---------------  S U M M A R Y ------------

Command Line: -Dorg.gradle.internal.worker.tmpdir=/home/[REDECATED]/github/MiraiCP/kotlin/shared/build/tmp/test/work -Dorg.gradle.native=false -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 3'

Host: 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz, 8 cores, 31G, Arch Linux
Time: Thu Aug  3 23:27:20 2023 CST elapsed time: 32.621992 seconds (0d 0h 0m 32s)

---------------  T H R E A D  ---------------

Current thread (0x00007f5d54235990):  VMThread "VM Thread" [stack: 0x00007f5d2d827000,0x00007f5d2d927000] [id=24037] _threads_hazard_ptr=0x00007f5c7007dba0

Stack: [0x00007f5d2d827000,0x00007f5d2d927000],  sp=0x00007f5d2d924400,  free space=1013k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x6dfa85]
V  [libjvm.so+0x6e0672]
V  [libjvm.so+0xeb35b3]
V  [libjvm.so+0x7d59ef]
V  [libjvm.so+0x7d5de9]
V  [libjvm.so+0x7d74a7]
V  [libjvm.so+0xf3cbb4]
V  [libjvm.so+0xf3e4c3]
V  [libjvm.so+0xf3e887]
V  [libjvm.so+0xf3ec2f]
V  [libjvm.so+0xeb78d2]
V  [libjvm.so+0xc59b3e]

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000000

... (下略)

网络日志

No response

补充信息

No response

HURUNZE commented 1 year ago

在创建 MockNormalMember 对象后,在开始运行其他任务或进行测试之前,调用 member.avatarUrl() 来初始化头像。

HURUNZE commented 1 year ago

在创建 MockNormalMember 对象后,在开始运行其他任务或进行测试之前,调用 member.avatarUrl() 来初始化头像。