Tempfile in Ruby deleted before garbage collection

Viewed 125

I have code like:

      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)

Inside GCE class methods there is code like:

        if !File.exist?(config[:json_cred])
          logger.error "Tempfile deleted: #{config[:avoid_garbage_collection]&.inspect}"
          raise
        end

Later during execution some 40% of the times the above fails. And the logged error is the expected:

[17:10:44] ERROR> Tempfile deleted: #<Tempfile:/home/jenkins/workspace/Runner-v3/workdir/json_cred_20200801-375-hqhu72 (closed)>

Any idea how it is possible that the tempfile becomes missing? Except for some external process deleting it, I see no other way. But also I don't see any such external process as this is a container based CI system and only the test process is running inside it. So I'm asking if there might be any other explanation that I'm missing.

This is with ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux].

0 Answers
Related