垃圾回收前删除Ruby中的Tempfile

垃圾回收前删除Ruby中的Tempfile,ruby,temporary-files,Ruby,Temporary Files,我有如下代码: json_file = Tempfile.new("json_cred_") json_file.write(auth_json) json_file.close return GCE.new(:json_cred => json_file.path, :auth_type => "json", :avoid_garbage_collect

我有如下代码:

      json_file = Tempfile.new("json_cred_")
      json_file.write(auth_json)
      json_file.close
      return GCE.new(:json_cred => json_file.path, :auth_type => "json",
                     :avoid_garbage_collection => json_file)

        if !File.exist?(config[:json_cred])
          logger.error "Tempfile deleted: #{config[:avoid_garbage_collection]&.inspect}"
          raise
        end
GCE
类方法中,有如下代码:

      json_file = Tempfile.new("json_cred_")
      json_file.write(auth_json)
      json_file.close
      return GCE.new(:json_cred => json_file.path, :auth_type => "json",
                     :avoid_garbage_collection => json_file)

        if !File.exist?(config[:json_cred])
          logger.error "Tempfile deleted: #{config[:avoid_garbage_collection]&.inspect}"
          raise
        end
稍后在执行过程中,上述操作失败的次数约占40%。并且记录的错误是预期的:

[17:10:44] ERROR> Tempfile deleted: #<Tempfile:/home/jenkins/workspace/Runner-v3/workdir/json_cred_20200801-375-hqhu72 (closed)>
[17:10:44]错误>临时文件已删除:#
你知道临时文件怎么会丢失吗?除了一些外部进程删除它,我看不到其他方法。但我也没有看到任何这样的外部进程,因为这是一个基于容器的CI系统,只有测试进程在其中运行。所以我在问是否还有其他我遗漏的解释

这是关于ruby 2.6.2p47(2019-03-13修订版67232)[x86_64-linux]

的评论,因为最近有人发了一篇类似的博文,但在评论中找到了他们问题的答案。