Skip to content
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

Loading activerecord-jdbcmysql-adapter crashes in JRuby 9.4.6.0 #8116

Closed
mohamedhafez opened this issue Feb 21, 2024 · 14 comments
Closed

Loading activerecord-jdbcmysql-adapter crashes in JRuby 9.4.6.0 #8116

mohamedhafez opened this issue Feb 21, 2024 · 14 comments
Milestone

Comments

@mohamedhafez
Copy link
Contributor

Running rails new . -d mysql fails with the following error, and the stacktrace at the bottom on JRuby 9.4.6.0, but works fine in 9.4.5.0. (Just trying to run the rails console in my application fails with the same error, just figured this was more reproducible)

Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-jdbcmysql-adapter'.
Gem Load Error is: class variable access from toplevel

Environment Information

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)
    jruby 9.4.6.0 (3.1.4) 2024-02-20 576fab2 OpenJDK 64-Bit Server VM 17.0.10+7-LTS on 17.0.10+7-LTS +jit [arm64-darwin]

  • Operating system and platform (e.g. uname -a)
    Darwin Mohameds-MacBook-Pro.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64

  • mysql -V
    mysql Ver 8.0.36 for macos14.2 on arm64 (Homebrew)

Other relevant info you may wish to add:

  • Installed or activated gems
    activerecord-jdbcmysql-adapter 61.2

  • Application/framework version (e.g. Rails, Sinatra)
    rails 6.1.7.6

Expected Behavior
creates a fresh rails project successfully

Actual Behavior

rubyprojects $ rails new rails6 -d mysql
      create  
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  .gitattributes
      create  Gemfile
         run  git init from "."
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /Users/mohamed/rubyprojects/rails6/.git/
      create  package.json
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/javascript/channels/consumer.js
      create  app/javascript/channels/index.js
      create  app/javascript/packs/application.js
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/spring
      create  bin/yarn
      remove  bin/spring
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_6_1.rb
      create  config/initializers/permissions_policy.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/pids
      create  tmp/pids/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/channels/application_cable/connection_test.rb
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_6_1.rb
         run  bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Bundle complete! 14 Gemfile dependencies, 80 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
       rails  webpacker:install
rails aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-jdbcmysql-adapter'.
Gem Load Error is: class variable access from toplevel
Backtrace for gem load error is:
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/mysql/connection_methods.rb:129:in `block in <main>'
org/jruby/RubyModule.java:3679:in `module_eval'
org/jruby/RubyModule.java:3710:in `module_eval'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/mysql/connection_methods.rb:2:in `<main>'
org/jruby/RubyKernel.java:1175:in `require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `block in require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/mysql.rb:3:in `<main>'
org/jruby/RubyKernel.java:1175:in `require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `block in require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbcmysql-adapter-61.2-java/lib/activerecord-jdbcmysql-adapter.rb:3:in `<main>'
org/jruby/RubyKernel.java:1175:in `require'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/bundler-2.5.6/lib/bundler/runtime.rb:60:in `block in require'
org/jruby/RubyArray.java:1983:in `each'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/bundler-2.5.6/lib/bundler/runtime.rb:55:in `block in require'
org/jruby/RubyArray.java:1983:in `each'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/bundler-2.5.6/lib/bundler/runtime.rb:44:in `require'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/bundler-2.5.6/lib/bundler.rb:187:in `require'
/Users/mohamed/rubyprojects/rails6/config/application.rb:7:in `<main>'
org/jruby/RubyKernel.java:1175:in `require'
org/jruby/RubyKernel.java:1204:in `require_relative'
/Users/mohamed/rubyprojects/rails6/Rakefile:4:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/rake-13.1.0/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/rake-13.1.0/lib/rake/application.rb:735:in `raw_load_rakefile'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/rake-13.1.0/lib/rake/application.rb:126:in `block in load_rakefile'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/rake-13.1.0/lib/rake/application.rb:125:in `load_rakefile'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/Users/mohamed/.rvm/rubies/jruby-9.4.6.0/lib/ruby/gems/shared/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/command.rb:50:in `invoke'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands.rb:18:in `<main>'
org/jruby/RubyKernel.java:1175:in `require'
bin/rails:4:in `<main>'
Bundler Error Backtrace:
/Users/mohamed/rubyprojects/rails6/config/application.rb:7:in `<main>'
/Users/mohamed/rubyprojects/rails6/Rakefile:4:in `<main>'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/command.rb:50:in `invoke'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands.rb:18:in `<main>'
bin/rails:4:in `<main>'

Caused by:
class variable access from toplevel
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/mysql/connection_methods.rb:129:in `block in <main>'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/mysql/connection_methods.rb:2:in `<main>'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `block in require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/mysql.rb:3:in `<main>'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `block in require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `require'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/activerecord-jdbcmysql-adapter-61.2-java/lib/activerecord-jdbcmysql-adapter.rb:3:in `<main>'
/Users/mohamed/rubyprojects/rails6/config/application.rb:7:in `<main>'
/Users/mohamed/rubyprojects/rails6/Rakefile:4:in `<main>'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/command.rb:50:in `invoke'
/Users/mohamed/.rvm/gems/jruby-9.4.6.0/gems/railties-6.1.7.6/lib/rails/commands.rb:18:in `<main>'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
@enebo
Copy link
Member

enebo commented Feb 21, 2024

The base problem is:

module Foo
end


Foo.module_eval {
  @@a = 1
}

This should raise in Ruby 3.1.x. I will try and get new releases out for mysql soon.

mshibuya added a commit to railsadminteam/rails_admin that referenced this issue Mar 2, 2024
@Confusion
Copy link

I will try and get new releases out for mysql soon.

That would be much appreciated; I'm also running into this issue.

@enebo
Copy link
Member

enebo commented Apr 8, 2024

@mohamedhafez @Confusion Sorry this got lost ☹️ I will get a version up soon but I realized at some point we accidentally removed a non-deprecated method which arjdbc relies on. I am working through to how to best make newer versions of arjdbc work with all supported JRuby releases. Next day or so.

@enebo
Copy link
Member

enebo commented Apr 9, 2024

61.3 has been released. If there is any other problem we will try and get the turnaround much quicker

@enebo enebo closed this as completed Apr 9, 2024
@enebo enebo added this to the Non-Release milestone Apr 29, 2024
@janko
Copy link

janko commented Apr 30, 2024

@enebo Will versions 60.x and 70.x of activerecord-jdbc-adapter also get patch releases? I'm running tests for sequel-activerecord_connection on Active Record 6.0+ on JRuby, and now 6.1 is passing but 6.0 and 7.0 are failing with this error.

@enebo
Copy link
Member

enebo commented Apr 30, 2024

@janko are you sure 70.2 is not working? https://rubygems.org/gems/activerecord-jdbc-adapter/versions/70.2-java

I had released that at the same time and it should have gotten the same fix.

I wasn't planning on updating 60.x but I can do that if you are still supporting it.

@janko
Copy link

janko commented Apr 30, 2024

Oh, you're right, the AR 7.0 test failed the same day JDBC adapter 70.2 was released, so it was still running 70.1 👍🏻

As for AR 6.0, I can just drop support for it on JRuby, people can just upgrade to AR 6.1.

@enebo
Copy link
Member

enebo commented Apr 30, 2024

@janko I am adding a couple of commits for 60 so I will put something out this morning. It looks like we are also still using starts_with? which I think Rails 6 removed. It will only effectively change sqlite3 (although unfortunately we end up releasing all adapters whether they change or not).

@janko
Copy link

janko commented Apr 30, 2024

Cool, thanks 👍🏻 FWIW, for me only the mysql2 adapter tests produce this error, sqlite3 works without issues.

@enebo
Copy link
Member

enebo commented Apr 30, 2024

@janko I take that back. There are other odd issues popping up. I am afraid to put something new out now. Something got deprecated and I can see someone changed general deps during 61 to include byebug. In general our policy for this is to not support anything Rails no longer supports itself and 6.0.x fell off the support table.

@enebo
Copy link
Member

enebo commented Apr 30, 2024

@janko mysql2? Really? Can you attach a gist. I only changed the cvar thing for sqlite3 and did not know we had that problem in mysql. Perhaps we addressed it for 70 before someone noticed it happening in sqlite3

@janko
Copy link

janko commented Apr 30, 2024

Here are the failing tests for the JRuby & AR 6.0 combination on my gem – https://github.com/janko/sequel-activerecord_connection/actions/runs/8618276360/job/23620255703. Some are legit failures, but most are RuntimeError: class variable access from toplevel, and coming from arjdbc's MySQL adapter.

RuntimeError: class variable access from toplevel
    vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-60.4-java/lib/arjdbc/mysql/connection_methods.rb:125:in `block in <main>'
    org/jruby/RubyModule.java:3679:in `module_eval'
    org/jruby/RubyModule.java:3710:in `module_eval'
    vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-60.4-java/lib/arjdbc/mysql/connection_methods.rb:2:in `<main>'
    org/jruby/RubyKernel.java:1175:in `require'
    vendor/bundle/jruby/3.1.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `block in require'
    vendor/bundle/jruby/3.1.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:[29](https://github.com/janko/sequel-activerecord_connection/actions/runs/8618276360/job/23620255703#step:6:30)1:in `load_dependency'
    vendor/bundle/jruby/3.1.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `require'
    vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-60.4-java/lib/arjdbc/mysql.rb:3:in `<main>'
    org/jruby/RubyKernel.java:1175:in `require'
    vendor/bundle/jruby/3.1.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:[32](https://github.com/janko/sequel-activerecord_connection/actions/runs/8618276360/job/23620255703#step:6:33)4:in `block in require'
    vendor/bundle/jruby/3.1.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:291:in `load_dependency'
    vendor/bundle/jruby/3.1.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `require'
    vendor/bundle/jruby/3.1.0/gems/activerecord-jdbc-adapter-60.4-java/lib/arjdbc/jdbc/adapter_require.rb:32:in `require'
    vendor/bundle/jruby/3.1.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
    vendor/bundle/jruby/3.1.0/gems/activerecord-6.0.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1058:in `establish_connection'
    vendor/bundle/jruby/3.1.0/gems/activerecord-6.0.6.1/lib/active_record/connection_handling.rb:51:in `establish_connection'
    test/test_helper.rb:155:in `activerecord_connect'
    test/test_helper.rb:59:in `connect_mysql2'
    test/mysql2_test.rb:5:in `block in <main>'
    org/jruby/RubyBasicObject.java:2532:in `instance_eval'
    org/jruby/RubyBasicObject.java:2560:in `instance_eval'

@janko
Copy link

janko commented Apr 30, 2024

Yeah, Active Record 6.0 being EOL is a completely legit reason for stopping support for it 👍🏻 I'm just used to supporting EOL versions of Rails & Ruby in my gems until they start posing a significant maintenance burden.

@enebo
Copy link
Member

enebo commented Apr 30, 2024

@janko ok interesting this on 60-stable is already fixed for mysql:

ee5562663 (Thomas E. Enebo 2024-02-21 10:03:30 -0500 125)   MYSQL_ENCODINGS = 
```

LOL.  I do not remember doing this.  So unless someone is desparate for another 60.x we will not be putting anything out.  The fixes are still here but I can see a potential sweater unravelling.  So let's say 60.x is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants