【问题标题】:Panic Related to Garbage Collector When Running Go Program运行 Go 程序时与垃圾收集器相关的恐慌
【发布时间】:2023-02-16 04:53:12
【问题描述】:

我从 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.

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

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

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

【问题讨论】:

    标签: go garbage-collection


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      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 runtime 升级到 go1.19

      【讨论】:

      • 谢谢。 ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.18 听起来有点吓人,是否意味着存在内存泄漏的风险?设置安全吗? Go 1.19 似乎还没有发布。
      • @edddd 我试图在我的评论中回答你的疑虑。 stackoverflow.com/a/75465252/1121052
      【解决方案3】:

      给遇到与此问题类似的错误的用户的说明。

      您的程序可能依赖于想要与垃圾收集器go4.org/intern 玩不安全游戏的模块。如果您更新工具链而不更新库,您的程序可能会因为内存损坏而退出。所以为了防止异常行为,程序panicked at startup。

      您可以通过某些方式处理恐慌:

      • 在你的依赖库上打开一个问题 (github.com/j3ssie/metabigor) repo as others do with similar problems。

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

      • 如果你确定你在做什么,你可以设置环境 变量ASSUME_NO_MOVING_GC_UNSAFE_RISK_IT_WITH=go1.VERSIONwhen you are not able to update自己的模块。您可以轻松地 从this line 找到未经测试的版本。基于this code,我认为设置环境变量作为临时解决方案是可以的,但要注意设置正确的值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-05
        • 1970-01-01
        • 2017-11-03
        • 1970-01-01
        • 1970-01-01
        • 2013-05-30
        相关资源
        最近更新 更多