运行 Go 程序时与垃圾收集器相关的恐慌

edd*_*ddd 5 garbage-collection go

我从 GitHub 安装了一个 Go 程序,当我运行它时,出现错误,

panic: Something in this program imports go4.org/unsafe/assume-no-moving-gc to declare that it assumes a non-moving garbage collector, but your version of go4.org/unsafe/assume-no-moving-gc hasn't been updated to assert that it's safe against the go1.18 runtime. If you want to risk it, run with environment variable ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.18 set. Notably, if go1.18 adds a moving garbage collector, this program is unsafe to use.
Run Code Online (Sandbox Code Playgroud)

似乎没有太多与此相关的信息。我的 Go 编码经验为零。

任何帮助深表感谢。我很乐意提供您可能需要的任何额外信息。

PS:我安装的程序是metabinor,它是用go install github.com/j3ssie/metabigor@latest.

小智 12

您也可以assume-no-moving-gc通过使用升级go get -u go4.org/unsafe/assume-no-moving-gc来解决这个问题。


小智 3

恐慌错误是由您导入的库触发的。

https://github.com/go4org/unsafe-assume-no-moving-gc/blob/main/untested.go

func init() {
    dots := strings.SplitN(runtime.Version(), ".", 3)
    v := runtime.Version()
    if len(dots) >= 2 {
        v = dots[0] + "." + dots[1]
    }
    if os.Getenv(env) == v {
        return
    }
    panic("Something in this program imports go4.org/unsafe/assume-no-moving-gc to declare that it assumes a non-moving garbage collector, but your version of go4.org/unsafe/assume-no-moving-gc hasn't been updated to assert that it's safe against the " + v + " runtime. If you want to risk it, run with environment variable " + env + "=" + v + " set. Notably, if " + v + " adds a moving garbage collector, this program is unsafe to use.")
}
Run Code Online (Sandbox Code Playgroud)

正如错误所说,你需要设置这个环境变量

ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.18
Run Code Online (Sandbox Code Playgroud)

或者,将 go 运行时升级到 go1.19