jruby / activerecord-jdbc-adapter

JRuby's ActiveRecord adapter using JDBC.
BSD 2-Clause "Simplified" License
462 stars 385 forks source link

Error starting rails 6.1.5 server & creating database on ARM64 Mac in JRuby 9.3.4.0 #1113

Open AndyObtiva opened 2 years ago

AndyObtiva commented 2 years ago
% uname -a
Darwin Andys-Lexop-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64

When running rails s from a rails 6.1.5 created app (rails new app_name) in JRuby 9.3.4.0 on an ARM64 (M1 Chip) Mac, I get the following error:

% rails s
=> Booting Puma
=> Rails 6.1.5.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.4 (jruby 9.3.4.0 - ruby 2.6.8) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 58156
* Listening on http://[::1]:3000
* Listening on http://127.0.0.1:3000
Use Ctrl-C to stop
Started GET "/" for 0:0:0:0:0:0:0:1 at 2022-05-03 13:05:47 -0400

ActiveRecord::JDBCError (Error opening connection):

arjdbc/jdbc/RubyJdbcConnection.java:532:in `initialize'
org/jruby/RubyClass.java:895:in `new'
activerecord-jdbc-adapter-61.2 (java) lib/arjdbc/abstract/core.rb:21:in `initialize'
activerecord-jdbc-adapter-61.2 (java) lib/arjdbc/sqlite3/adapter.rb:87:in `initialize'
activerecord-jdbc-adapter-61.2 (java) lib/arjdbc/abstract/statement_cache.rb:23:in `initialize'
org/jruby/RubyClass.java:909:in `new'
activerecord-jdbc-adapter-61.2 (java) lib/arjdbc/jdbc/connection_methods.rb:10:in `jdbc_connection'
activerecord-jdbc-adapter-61.2 (java) lib/arjdbc/sqlite3/connection_methods.rb:59:in `sqlite3_connection'
org/jruby/RubyKernel.java:2003:in `public_send'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
activerecord (6.1.5.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
activerecord (6.1.5.1) lib/active_record/connection_handling.rb:327:in `retrieve_connection'
activerecord (6.1.5.1) lib/active_record/connection_handling.rb:283:in `connection'
activerecord (6.1.5.1) lib/active_record/migration.rb:611:in `connection'
activerecord (6.1.5.1) lib/active_record/migration.rb:606:in `build_watcher'
activerecord (6.1.5.1) lib/active_record/migration.rb:588:in `block in call'
org/jruby/ext/thread/Mutex.java:171:in `synchronize'
activerecord (6.1.5.1) lib/active_record/migration.rb:587:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.1.5.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (6.1.5.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
org/jruby/RubyKernel.java:1237:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.1.5.1) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.1.5.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.1.5.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (6.1.5.1) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (6.1.5.1) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (6.1.5.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.1.5.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/static.rb:24:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.1.5.1) lib/action_dispatch/middleware/host_authorization.rb:148:in `call'
rack-mini-profiler (2.3.4) lib/mini_profiler/profiler.rb:393:in `call'
webpacker (5.4.3) lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
rack-proxy (0.7.2) lib/rack/proxy.rb:67:in `call'
railties (6.1.5.1) lib/rails/engine.rb:539:in `call'
puma-5.6.4 (java) lib/puma/configuration.rb:252:in `call'
puma-5.6.4 (java) lib/puma/request.rb:77:in `block in handle_request'
puma-5.6.4 (java) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
puma-5.6.4 (java) lib/puma/request.rb:76:in `handle_request'
puma-5.6.4 (java) lib/puma/server.rb:441:in `process_client'
puma-5.6.4 (java) lib/puma/thread_pool.rb:147:in `block in spawn_thread'

NoMethodError: undefined method `bindings' for #<Java::JavaSql::SQLException: Error opening connection>
Did you mean?  binding
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/web-console-4.2.0/lib/web_console/exception_mapper.rb:25:in `initialize'
    from org/jruby/RubyClass.java:888:in `new'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/web-console-4.2.0/lib/web_console/exception_mapper.rb:11:in `follow'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/web-console-4.2.0/lib/web_console/session.rb:34:in `from'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/web-console-4.2.0/lib/web_console/middleware.rb:30:in `block in call'
    from org/jruby/RubyKernel.java:1237:in `catch'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/web-console-4.2.0/lib/web_console/middleware.rb:17:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/actionpack-6.1.5.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/railties-6.1.5.1/lib/rails/rack/logger.rb:37:in `call_app'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/railties-6.1.5.1/lib/rails/rack/logger.rb:26:in `block in call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/activesupport-6.1.5.1/lib/active_support/tagged_logging.rb:99:in `block in tagged'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/activesupport-6.1.5.1/lib/active_support/tagged_logging.rb:37:in `tagged'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/activesupport-6.1.5.1/lib/active_support/tagged_logging.rb:99:in `tagged'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/railties-6.1.5.1/lib/rails/rack/logger.rb:26:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/sprockets-rails-3.4.2/lib/sprockets/rails/quiet_assets.rb:13:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/actionpack-6.1.5.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/actionpack-6.1.5.1/lib/action_dispatch/middleware/request_id.rb:26:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/activesupport-6.1.5.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/actionpack-6.1.5.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/actionpack-6.1.5.1/lib/action_dispatch/middleware/static.rb:24:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/actionpack-6.1.5.1/lib/action_dispatch/middleware/host_authorization.rb:148:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/rack-mini-profiler-2.3.4/lib/mini_profiler/profiler.rb:393:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/webpacker-5.4.3/lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/rack-proxy-0.7.2/lib/rack/proxy.rb:67:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/railties-6.1.5.1/lib/rails/engine.rb:539:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/puma-5.6.4-java/lib/puma/configuration.rb:252:in `call'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/puma-5.6.4-java/lib/puma/request.rb:77:in `block in handle_request'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/puma-5.6.4-java/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/puma-5.6.4-java/lib/puma/request.rb:76:in `handle_request'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/puma-5.6.4-java/lib/puma/server.rb:441:in `process_client'
    from /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@code/gems/puma-5.6.4-java/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2022-05-03 13:06:11 -0400 ===
- Goodbye!
Exiting

I tried running rails db:create next, but I got an error too:

% rails db:create
Error opening connection
Couldn't create 'db/development.sqlite3' database. Please check your configuration.
rails aborted!
ActiveRecord::JDBCError: Error opening connection

Caused by:
Java::JavaSql::SQLException: Error opening connection

Caused by:
Java::JavaLang::Exception: No native library is found for os.name=Mac and os.arch=aarch64. path=/org/sqlite/native/Mac/aarch64

Tasks: TOP => db:create
(See full trace by running task with --trace)

These seem like ARM64 (AARCH64) related issues because I can run the same commands just fine on my Intel Mac from JRuby 9.3.4.0.

headius commented 1 year ago

I missed this but here's the situation... We did release an updated jdbc-sqlite3 gem that includes Mac M1 support, but unfortunately the 60/61.x adapters are pinned to lower versions for some reason:

Bundler could not find compatible versions for gem "jdbc-sqlite3":
  In Gemfile:
    jdbc-sqlite3 (= 3.42.0.0)

    activerecord-jdbcsqlite3-adapter was resolved to 61.2, which depends on
      jdbc-sqlite3 (~> 3.8, < 3.30)

I don't know why we have it boxed this way, but it would be worth releasing updates for 60 and 61 that update the sqlite driver.

cc @kares @enebo

headius commented 1 year ago

I've pushed #1137 to address this for 61.x. I believe 70.x already is working with newest jdbc-sqlite3.