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

huangapple go评论125阅读模式
英文:

Panic Related to Garbage Collector When Running Go Program

问题

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

panic: 这个程序中的某些部分导入了go4.org/unsafe/assume-no-moving-gc来声明它假设使用非移动垃圾收集器,但你的go4.org/unsafe/assume-no-moving-gc版本还没有更新以断言它对go1.18运行时是安全的。如果你想冒险,可以设置环境变量ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.18。值得注意的是,如果go1.18添加了移动垃圾收集器,这个程序是不安全的。

看起来关于这个问题的相关信息并不多。我对Go编程没有任何经验。

非常感谢任何帮助。如果你需要任何额外的信息,我很乐意提供。

PS:我安装的程序是metabignor,使用go install github.com/j3ssie/metabigor@latest进行安装。

英文:

I installed a Go program from GitHub and when I run it, I get the error,

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.

It appears that there isn't much information related to this out there. I have zero experience coding in Go.

Any help is much appreciated. I'll be happy to provide any extra information you might need.

PS: The program I installed is metabignor and it was installed with go install github.com/j3ssie/metabigor@latest.

答案1

得分: 12

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

英文:

you can also upgrade assume-no-moving-gc by using go get -u go4.org/unsafe/assume-no-moving-gc to solve this problem.

答案2

得分: 4

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

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.")
}

根据错误提示,你需要设置这个环境变量:

ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.18

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

英文:

the panic error is triggered by the library you imported.

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.")
}

as what the error said, you need to set this env var

ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.18

or, upgrade the go runtime to go1.19

答案3

得分: 0

给那些遇到类似错误的用户的一条提示:

你的程序可能依赖于那些试图与垃圾收集器玩不安全游戏的模块[go4.org/intern]。如果你更新了工具链但没有更新库,你的程序可能因为内存损坏而退出。所以为了防止异常行为,程序在启动时会发生panic。

你可以通过以下几种方式处理panic:

  • 在你的依赖库的仓库上提交一个issue(github.com/j3ssie/metabigor),就像其他人遇到类似问题时所做的那样。

  • 当你能够更新该模块时,自己更新模块也是非常安全的(go get -u go4.org/unsafe/assume-no-moving-gc)。

  • 如果你确定自己在做什么,当你无法自己更新模块时,你可以设置环境变量ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.VERSION。你可以从这一行代码中轻松找到未经测试的VERSION。根据这段代码,我认为将环境变量设置为临时解决方案是可以的,但要小心设置正确的值。

英文:

A note for users that come from similar errors to this issue.

Your program may depend on the modules that want to play unsafe games with the garbage collector go4.org/intern. If you update the toolchain without updating the library, your program may be exited because of memory corruption. So to prevent unusual behavior the program panicked at startup.

You can handle the panic in some ways:

  • Open an issue on your dependency library
    (github.com/j3ssie/metabigor) repo as others do with similar problems.

  • It's really safe to update the module yourself too (go get -u go4.org/unsafe/assume-no-moving-gc) when you can update the module.

  • If you are sure what are you doing you can set the environment
    variable ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.VERSION when
    you are not able to update
    the module yourself. You can easily
    find the not tested VERSION from this line. Based on this code, I think it is fine to set the environment variable as a temporary solution but be careful to set the proper value.

huangapple
  • 本文由 发表于 2022年4月20日 23:26:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/71942328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定