ea6a84f336
The Ruby Tempfile class has a finalizer that removes the file when the GC runs. It's not predictible when the GC will run, so you have to ensure that the instance of the class stays in scope for as long as you need it. Unfortunately the tempfile method is returning just the filename of the temporary file, which means it goes out of scope when that method returns. This allows the GC to reap it at any time after return. In both CI and production environments we've seen this race fail, causing apt-key add to fail a small (2-3%) amount of the time. This changes the tempfile and source_to_file methods to return the underlying Tempfile object, pushing it up into the caller's scope. Both of the callers immediately use the object to get its filename and then open the file, eliminating the race. Tested this by adding 'GC.start; sleep(1)' immediately before the command is run, to give the GC plenty of time to remove the tempfile if it was going to. |
||
---|---|---|
.. | ||
apt_key.rb |