
Issue #20611 has been updated by jbw (Jerry W). I just realised now that Tempfile is atually a separate gem. Looking there I can see that the size method is using its internal buffer length if the file is not closed, otherwise it falls back on File.size. Now it's become clear to me that the reason I'm seeing this bug is because my Tempfile too must be modified outside of its instance and this is causing this bug to be manifested on modern rubies. You can close this, sorry for wasting your time ---------------------------------------- Bug #20611: Ruby 3.3: Tempfile#size returns 0 when file is not empty https://bugs.ruby-lang.org/issues/20611#change-108996 * Author: jbw (Jerry W) * Status: Open * ruby -v: 3.3.3 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Hi I searched to see if this was reported already, or if it was somehow intentional but I'm having an issue with Ruby 3.3.3. I run under rbenv 2.7.6 on amd64 linux (debian 6.6.13-1 kernel). For me, ruby 3.3.3 exhibits some oddness with the Tempfile class whereas Ruby 3.2 and older does not. I have only tested ruby 3.3.3 not other 3.3.x releases: ff = Tempfile.new('foo'); puts "Size now: #{ff.size}"; File.open(ff.path, "a").tap {|f|| f.write('moredata'); f.close } ; puts "Finish size: #{ff.size} vs actual: #{File.size(ff.path)}" Size now: 0 Finish size: 0 vs actual: 8 As you can see, ff.size should have returned 8. If i try the same code on ruby 3.2.2 for example it works as expected: ff = Tempfile.new('foo'); puts "Size now: #{ff.size}"; File.open(ff.path, "a").tap {|f| f.write('moredata'); f.close } ; ff.size; puts "Finish size: #{ff.size} vs actual: #{File.size(ff.path)}" Size now: 0 Finish size: 8 vs actual: 8 -- https://bugs.ruby-lang.org/