itamae: Bug where time could not be handled correctly in a Docker environment with Ruby 3.4

About

github.com/itamae-kitchen#297 causes CI to fail only in Ruby 3.4.

This repository is for verifying the above bug.

Environment

$ uname -a
Linux dsk 6.11.0-24-generic #24~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 25 20:14:34 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS"
$ which ruby
/home/linuxbrew/.linuxbrew/bin/ruby
$ ruby -v
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]

How to reproduce

$ git clone https://github.com/takumin/poc-itamae-ruby-3-4-bug-repro.git
$ cd poc-itamae-ruby-3-4-bug-repro
$ bundle config set bin '.bin'
$ bundle config set path '.bundle'
$ bundle install
$ bundle exec rake

Details

All tests pass in Ruby 3.3, but the following error occurs in Ruby 3.4:

Ruby 3.4 Serverspec log

Ruby 3.4 Serverspec log

File "/tmp/file_edit_with_content_change_updates_timestamp"
  mtime
    is expected to be > 2016-05-02T01:23:45+00:00 (FAILED - 1)
File "/tmp/file_with_content_change_updates_timestamp"
  mtime
    is expected to be > 2016-05-01T01:23:45+00:00 (FAILED - 2)
Failures:

  1) File "/tmp/file_edit_with_content_change_updates_timestamp" mtime is expected to be > 2016-05-02T01:23:45+00:00
     Failure/Error: its(:mtime) { should be > DateTime.iso8601("2016-05-02T01:23:45Z") }
       expected: > #<DateTime: 2016-05-02T01:23:45+00:00 ((2457511j,5025s,0n),+0s,2299161j)>
            got:   #<DateTime: 1980-01-02T09:00:00+09:00 ((2444241j,0s,0n),+32400s,2299161j)>

     # ./spec/integration/default_spec.rb:287:in 'block (2 levels) in <top (required)>'

  2) File "/tmp/file_with_content_change_updates_timestamp" mtime is expected to be > 2016-05-01T01:23:45+00:00
     Failure/Error: its(:mtime) { should be > DateTime.iso8601("2016-05-01T01:23:45Z") }
       expected: > #<DateTime: 2016-05-01T01:23:45+00:00 ((2457510j,5025s,0n),+0s,2299161j)>
            got:   #<DateTime: 1980-01-02T09:00:00+09:00 ((2444241j,0s,0n),+32400s,2299161j)>

     # ./spec/integration/default_spec.rb:319:in 'block (2 levels) in <top (required)>'

Finished in 3.06 seconds (files took 0.23664 seconds to load)
153 examples, 2 failures, 2 pending

Failed examples:

rspec ./spec/integration/default_spec.rb:287 # File "/tmp/file_edit_with_content_change_updates_timestamp" mtime is expected to be > 2016-05-02T01:23:45+00:00
rspec ./spec/integration/default_spec.rb:319 # File "/tmp/file_with_content_change_updates_timestamp" mtime is expected to be > 2016-05-01T01:23:45+00:00

This is the code where I think the problem is occurring.

The code where the error occurs

The code where the error occurs

itamae/spec/integration/recipes/default.rb#L458-L465

execute "f=/tmp/file_edit_with_content_change_updates_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-02T01:23:45Z $f"

file "/tmp/file_edit_with_content_change_updates_timestamp" do
  action :edit
  block do |content|
    content.gsub!('world', 'Itamae')
  end
end

itamae/spec/integration/recipes/default.rb#L498-L502

execute "f=/tmp/file_edit_with_content_change_updates_timestamp && echo 'Hello, world' > $f && touch -d 2016-05-02T01:23:45Z $f"

file "/tmp/file_edit_with_content_change_updates_timestamp" do
  action :edit
  block do |content|
    content.gsub!('world', 'Itamae')
  end
end

itamae/spec/integration/default_spec.ruby#L275-L277

describe file('/tmp/file_edit_with_content_change_updates_timestamp') do
  its(:mtime) { should be > DateTime.iso8601("2016-05-02T01:23:45Z") }
end

itamae/spec/integration/default_spec.ruby#L307-L309

describe file('/tmp/file_with_content_change_updates_timestamp') do
  its(:mtime) { should be > DateTime.iso8601("2016-05-01T01:23:45Z") }
end

References

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

Hey, I’m the RubyGems maintainer that made the relevant change — sorry for the trouble! We didn’t realize anyone was relying on the mtime value, since we’d previously changed it without issue. 😅

I left a reply to @unasuke at https://github.com/rubygems/rubygems/pull/8568#issuecomment-2840380427 with more details on the reason for the change, but in terms of fixing your immediate problem, this is the important info:

  1. The default mtime value should be treated as an implementation detail.
  2. If you do rely on the mtime value, you can control it via the SOURCE_DATE_EPOCH environment variable.

To restore the previous behavior, you need to set SOURCE_DATE_EPOCH to the time the build process started (as a UNIX timestamp).

In Ruby, that’d be:

ENV['SOURCE_DATE_EPOCH'] = Time.now.to_i.to_s

If you’re calling gem build/rake build from a Bash script, you can do:

export SOURCE_DATE_EPOCH=$(date '+%s')

@takumin Your notes helped my investigation and upstream report. Thank you, too!

memo

  • Ruby 3.4.3 & rubygems v3.6.6 → pass
  • Ruby 3.4.3 & rubygems v3.6.7 → fail

I bisected ruby’s commits. So I found https://github.com/ruby/ruby/commit/e580145171c16d3ca31ee0732e3ed87ff7dfd774. But it’s sync commit from rubygems and bundler, finding root cause is hard…I still investigating.

I reproduced it. Investigating it…