Thanks to visit codestin.com
Credit goes to github.com

Skip to content

>= 0.4.20 broken on ruby 3.0 #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
glaszig opened this issue May 5, 2025 · 14 comments Β· Fixed by #474
Closed

>= 0.4.20 broken on ruby 3.0 #471

glaszig opened this issue May 5, 2025 · 14 comments Β· Fixed by #474
Labels
bug Something isn't working

Comments

@glaszig
Copy link

glaszig commented May 5, 2025

eager loading fails with the following:

$ rake --trace
rake aborted!
NoMethodError: undefined method `include?' for false:FalseClass
Code/net-imap/lib/net/imap/config/attr_type_coercion.rb:57:in `block (3 levels) in <module:AttrTypeCoercion>'
Code/net-imap/lib/net/imap/config/attr_type_coercion.rb:47:in `block in attr_accessor'
Code/net-imap/lib/net/imap/config.rb:404:in `block in update'
Code/net-imap/lib/net/imap/config.rb:404:in `each'
Code/net-imap/lib/net/imap/config.rb:404:in `update'
Code/net-imap/lib/net/imap/config.rb:386:in `initialize'
Code/net-imap/lib/net/imap/config.rb:452:in `new'
Code/net-imap/lib/net/imap/config.rb:452:in `<class:Config>'
Code/net-imap/lib/net/imap/config.rb:120:in `<class:IMAP>'
Code/net-imap/lib/net/imap/config.rb:8:in `<module:Net>'
Code/net-imap/lib/net/imap/config.rb:7:in `<top (required)>'
Code/net-imap/lib/net/imap.rb:3172:in `require_relative'
Code/net-imap/lib/net/imap.rb:3172:in `<top (required)>'
Code/net-imap/rakelib/rdoc.rake:3:in `require_relative'
Code/net-imap/rakelib/rdoc.rake:3:in `<top (required)>'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/rake_module.rb:29:in `load'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/rake_module.rb:29:in `load_rakefile'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/default_loader.rb:11:in `load'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:818:in `load_imports'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:748:in `raw_load_rakefile'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:126:in `block in load_rakefile'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:125:in `load_rakefile'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:82:in `block in run'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/lib/rake/application.rb:80:in `run'
.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
.rbenv/versions/3.0.2/bin/rake:23:in `load'
.rbenv/versions/3.0.2/bin/rake:23:in `<main>'

i nailed this down to the use of Ractor.make_shareable. it works when i remove that code path (config/attr_type_coercion.rb:31-33).

$ sw_vers
ProductName:	macOS
ProductVersion:	12.7.6
$ ruby --version
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin21]
@glaszig
Copy link
Author

glaszig commented May 5, 2025

from my research it seems that Ractor.make_shareable in ruby 3.0 has issues with procs. so, with the ractor use in the 0.4 branch, this branch effectively requires ruby 3.1 now -- different from what the gemspec states (required_ruby_version = Gem::Requirement.new(">= 2.7.3")).

i think the ractor approach should be exclusive to the master branch, i.e., with required ruby >= 3.1.

@nevans
Copy link
Collaborator

nevans commented May 5, 2025

Thanks for diagnosing that. Your diagnosis (Reactor.make_shareable has issues with with Proc) sounds correct.

But I wonder why this never failed in CI. It also passed for me locally... with 3.0.7. I suspect this was a bug in 3.0.2. Looking at the commits, I suspect it was fixed in 3.0.3 (2021-11-24) or maybe 3.0.4 (2022-04-12). Since versions 3.0.3 through 3.0.7 all contain security fixes, I strongly recommend upgrading to 3.0.7 ASAP. (Since ruby 3.0 and ruby 3.1 are both EOL, that should be upgraded too, but I know that upgrading to a new ruby release can be a bigger project.)

On the one hand, I'm not inclined to workaround bugs in ruby which have been already fixed for over three years... especially for EOL ruby versions.

On the other hand, Ractor was new and experimental for ruby 3.0. so I should not have expected it to work smoothly. And this is only one tiny step (of many) towards making Net::IMAP Ractor compatible. And this same code also caused problems for JRuby/TruffleRuby projects. I really should not have included that code in the v0.4-stable branch.

I'd welcome a PR to remove the Ractor code from the v0.4-stable branch (or I'll get to it myself by the end of the week).

@nevans
Copy link
Collaborator

nevans commented May 5, 2025

Tangentially, I didn't think net-imap would be loaded by a rails app unless you're actually using it, even with config.eager_load = true. But:

The stacktrace you posted comes from working on net-imap locally, and not from the rails app, right? Because your rails app definitely should not be loading net-imap's rakelib/*.rake.

@nevans nevans added the bug Something isn't working label May 5, 2025
@mumkymikey
Copy link

mumkymikey commented May 5, 2025

hi @nevans, i've run into the same issue with >= 0.4.20 of net-imap as well. this is just when running rspec tests locally.

@glaszig
Copy link
Author

glaszig commented May 5, 2025

The stacktrace you posted comes from working on net-imap locally, and not from the rails app, right? Because your rails app definitely should not be loading net-imap's rakelib/*.rake.

yes, the stack trace was from the net-imap source but the issue arose in a rails app that has eager_loading = true in ci and production. the code path you described above is correct, that's what lead me here.

@glaszig
Copy link
Author

glaszig commented May 5, 2025

I didn't think net-imap would be loaded by a rails app unless you're actually using it, even with config.eager_load = true

the railtie in actionmailer adds itself (ActionMailer module) to config.eager_load_namespaces over which the railties gem iterates and calls eager_load() on each (if app.config.eager_load = true).

@glaszig
Copy link
Author

glaszig commented May 5, 2025

fwiw here's the stack trace from ci.

./net-imap-0.4.21/lib/net/imap/config/attr_type_coercion.rb:57:in `block (3 levels) in <module:AttrTypeCoercion>': undefined method `include?' for false:FalseClass (NoMethodError)
  from ./net-imap-0.4.21/lib/net/imap/config/attr_type_coercion.rb:47:in `block in attr_accessor'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:404:in `block in update'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:404:in `each'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:404:in `update'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:386:in `initialize'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:452:in `new'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:452:in `<class:Config>'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:120:in `<class:IMAP>'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:8:in `<module:Net>'
  from ./net-imap-0.4.21/lib/net/imap/config.rb:7:in `<main>'
  from ./net-imap-0.4.21/lib/net/imap.rb:3172:in `require_relative'
  from ./net-imap-0.4.21/lib/net/imap.rb:3172:in `<main>'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  from ./mail-2.8.1/lib/mail/network/retriever_methods/imap.rb:40:in `<class:IMAP>'
  from ./mail-2.8.1/lib/mail/network/retriever_methods/imap.rb:39:in `<module:Mail>'
  from ./mail-2.8.1/lib/mail/network/retriever_methods/imap.rb:4:in `<main>'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  from ./mail-2.8.1/lib/mail.rb:36:in `block in eager_autoload!'
  from ./mail-2.8.1/lib/mail.rb:36:in `each'
  from ./mail-2.8.1/lib/mail.rb:36:in `eager_autoload!'
  from ./actionmailer-7.1.5.1/lib/action_mailer.rb:65:in `eager_load!'
  from ./railties-7.1.5.1/lib/rails/application/finisher.rb:81:in `each'
  from ./railties-7.1.5.1/lib/rails/application/finisher.rb:81:in `block in <module:Finisher>'
  from ./railties-7.1.5.1/lib/rails/initializable.rb:32:in `instance_exec'
  from ./railties-7.1.5.1/lib/rails/initializable.rb:32:in `run'
  from ./railties-7.1.5.1/lib/rails/initializable.rb:61:in `block in run_initializers'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `call'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
  from /usr/local/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
  from ./railties-7.1.5.1/lib/rails/initializable.rb:60:in `run_initializers'
  from ./railties-7.1.5.1/lib/rails/application.rb:426:in `initialize!'
  from /drone/src/config/environment.rb:5:in `<main>'
  from /drone/src/test/test_helper.rb:2:in `require_relative'
  from /drone/src/test/test_helper.rb:2:in `<main>'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  from /drone/src/test/channels/lock_integration_service_object_channel_test.rb:1:in `<main>'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  from ./railties-7.1.5.1/lib/rails/test_unit/runner.rb:51:in `block in load_tests'
  from ./railties-7.1.5.1/lib/rails/test_unit/runner.rb:51:in `each'
  from ./railties-7.1.5.1/lib/rails/test_unit/runner.rb:51:in `load_tests'
  from ./railties-7.1.5.1/lib/rails/test_unit/runner.rb:43:in `run'
  from ./railties-7.1.5.1/lib/rails/commands/test/test_command.rb:33:in `perform'
  from ./thor-1.3.2/lib/thor/command.rb:28:in `run'
  from ./thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
  from ./railties-7.1.5.1/lib/rails/command/base.rb:178:in `invoke_command'
  from ./thor-1.3.2/lib/thor.rb:538:in `dispatch'
  from ./railties-7.1.5.1/lib/rails/command/base.rb:73:in `perform'
  from ./railties-7.1.5.1/lib/rails/command.rb:71:in `block in invoke'
  from ./railties-7.1.5.1/lib/rails/command.rb:149:in `with_argv'
  from ./railties-7.1.5.1/lib/rails/command.rb:69:in `invoke'
  from ./railties-7.1.5.1/lib/rails/commands.rb:18:in `<main>'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from ./bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  from bin/rails:4:in `<main>'

@nevans
Copy link
Collaborator

nevans commented May 6, 2025

hi @nevans, i've run into the same issue with >= 0.4.20 of net-imap as well. this is just when running rspec tests locally.

@mumkymikey Thanks for adding your report. What version of ruby are you running? 3.0.0-3.0.2? 3.0.3? 3.0.4? 3.0.5-3.0.7?

nevans added a commit that referenced this issue May 6, 2025
This was just one piece of making config objects ractor sharableβ€”it is
insufficient by itself.  And it caused problems with earlier versions of
ruby 3.0.  It should not have been committed to the v0.4-stable branch.

Fixes: #471
Reported-by: @glaszig
Reported-by: @mumkymikey
@nevans nevans linked a pull request May 6, 2025 that will close this issue
@nevans
Copy link
Collaborator

nevans commented May 6, 2025

FYI: I just installed 3.0.3 locally, and (after upgrading rubygems so the tests could run) verified that v0.4.20 works fine with ruby 3.0.3.

Important

ruby 3.0.3 was released almost three and a half years ago. It (and every other 3.0.x release) contains security fixes and bug fixes. Even if you don't have the time to upgrade to 3.1+, please prioritize updating to the latest patch release of your ruby version! Patch releases are low risk: very unlikely to cause bugs and very likely to fix some.

@nevans
Copy link
Collaborator

nevans commented May 6, 2025

Okay... I've released v0.4.22 with the fix (#474)...

Or at least, I assume that #474 fixes it. Because I can't reproduce this issue locally, even with ruby 3.0.2. I'm guessing that it may be architecture dependent. I'm using Linux, so maybe x86-linux is okay but x86_64-darwin or arm64-darwin is not?

@glaszig, @mumkymikey, if you have the time, and to help out others who run into this, can you please:

  • post your gem env platform
  • find the first patch release of 3.0 that does not exhibit the bug and post that. I'm assuming that the bug is fixed by either 3.0.3 or 3.0.4. I know that CI is passing for both macos-latest and ubuntu-latest with 3.0.7.

If that v0.4.22 doesn't fix it, I'm going to need someone who can reproduce the issue to submit a PR. :)

Thanks!

@nevans nevans closed this as completed May 6, 2025
@mumkymikey
Copy link

@nevans the issue seems to be resolved with v0.4.22, thanks for the quick help here!!

@nevans
Copy link
Collaborator

nevans commented May 6, 2025

@mumkymikey great! If you have a moment, can you confirm your ruby -e 'puts RUBY_VERSION and gem env platform?

@mumkymikey
Copy link

sure!

$ ruby -e 'puts RUBY_VERSION'
3.0.0

$ gem env platform
ruby:x86_64-darwin-22

@glaszig
Copy link
Author

glaszig commented May 6, 2025

$ gem env platform
ruby:arm64-darwin-21

0.4.22 works for me. passes ci where 0.4.21 failed. thank you.

can also confirm that on ruby 3.0.3 the issue is not present with v0.4.21 as follows.

$ podman run --rm -it -v ${PWD}:/src -w /src docker.io/library/ruby:3.0.2 bash -c 'git branch && ruby --version && bundle --quiet && bundle exec rake'
* (HEAD detached at 644a5d1)
  master
  v0.4-stable
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [aarch64-linux]
rake aborted!
NoMethodError: undefined method `include?' for false:FalseClass
/src/lib/net/imap/config/attr_type_coercion.rb:57:in `block (3 levels) in <module:AttrTypeCoercion>'
/src/lib/net/imap/config/attr_type_coercion.rb:47:in `block in attr_accessor'
/src/lib/net/imap/config.rb:404:in `block in update'
/src/lib/net/imap/config.rb:404:in `each'
/src/lib/net/imap/config.rb:404:in `update'
/src/lib/net/imap/config.rb:386:in `initialize'
/src/lib/net/imap/config.rb:452:in `new'
/src/lib/net/imap/config.rb:452:in `<class:Config>'
/src/lib/net/imap/config.rb:120:in `<class:IMAP>'
/src/lib/net/imap/config.rb:8:in `<module:Net>'
/src/lib/net/imap/config.rb:7:in `<top (required)>'
/src/lib/net/imap.rb:3172:in `require_relative'
/src/lib/net/imap.rb:3172:in `<top (required)>'
/src/rakelib/rdoc.rake:3:in `require_relative'
/src/rakelib/rdoc.rake:3:in `<top (required)>'
/usr/local/bundle/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)
$ podman run --rm -it -v ${PWD}:/src -w /src docker.io/library/ruby:3.0.3 bash -c 'git branch && ruby --version && bundle --quiet && bundle exec rake'
* (HEAD detached at 644a5d1)
  master
  v0.4-stable
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [aarch64-linux]
Loaded suite /usr/local/bundle/gems/rake-13.2.1/lib/rake/rake_test_loader
Started
Finished in 19.084379245 seconds.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
908 tests, 10107 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
47.58 tests/s, 529.60 assertions/s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants