Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Rails 4.0.2 + trinidad_postgresql_dbpool_extension error #12

Closed
mmmries opened this issue Dec 10, 2013 · 5 comments
Closed

Rails 4.0.2 + trinidad_postgresql_dbpool_extension error #12

mmmries opened this issue Dec 10, 2013 · 5 comments

Comments

@mmmries
Copy link

mmmries commented Dec 10, 2013

I am upgrading a rails 3.2 app to rails 4.0.2 with trindad and jdbcpostgresql.

When the first activerecord model gets required and it uses the table_exists? to check for table existence I get the failure: 'Java::JavaLang::ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.postgresql.PGConnection'

This only occurs when using the trinidad_postgresql_dbpool_extension.

Here is a more complete stack trace.

2013-12-09 17:07:06 -0700 INFO: Java::JavaLang::ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.postgresql.PGConnection:         SELECT COUNT(*) as table_count
        FROM pg_tables
        WHERE tablename = ?
        AND schemaname = ANY (current_schemas(false))

2013-12-09 17:07:06 -0700 INFO: An exception happened during JRuby-Rack startup
No such file to load -- java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.postgresql.PGConnection
--- System
jruby 1.7.8 (1.9.3p392) 2013-11-14 0ce429e on OpenJDK 64-Bit Server VM 1.7.0_25-b30 [linux-amd64]
Time: 2013-12-09 17:07:06 -0700
Server: Apache Tomcat/7.0.42
jruby.home: /usr/local/rvm/rubies/jruby-1.7.8

--- Context Init Parameters:
jruby.compat.version = 1.9.3
jruby.initial.runtimes = 1
jruby.max.runtimes = 1
jruby.min.runtimes = 1
jruby.rack.error = false
jruby.rack.layout_class = JRuby::Rack::FileSystemLayout
jruby.rack.logging = JUL
jruby.rack.logging.name = org.apache.catalina.core.ContainerBase.[Tomcat].[0.0.0.0].[default]
jruby.runtime.acquire.timeout = 5.0
public.root = public
rails.env = sandbox
rails.root = /srv/synchronicity/releases/20131210000248

--- Backtrace
LoadError: No such file to load -- java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.postgresql.PGConnection
                                 require at org/jruby/RubyKernel.java:1084
                                 require at /srv/synchronicity/shared/bundle/jruby/1.9/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229
                         load_dependency at /srv/synchronicity/shared/bundle/jruby/1.9/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214
                                 require at /srv/synchronicity/shared/bundle/jruby/1.9/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229
                         require_or_load at /srv/synchronicity/shared/bundle/jruby/1.9/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:330
                               depend_on at /srv/synchronicity/shared/bundle/jruby/1.9/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:289
                      require_dependency at /srv/synchronicity/shared/bundle/jruby/1.9/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:207
                             eager_load! at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/engine.rb:465
                                    each at org/jruby/RubyArray.java:1613
                             eager_load! at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/engine.rb:464
                                    each at org/jruby/RubyArray.java:1613
                             eager_load! at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/engine.rb:462
                             eager_load! at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/engine.rb:347
                                    each at org/jruby/RubyArray.java:1613
                                Finisher at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/application/finisher.rb:56
                           instance_exec at org/jruby/RubyBasicObject.java:1565
                                     run at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/initializable.rb:30
                        run_initializers at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/initializable.rb:55
                              tsort_each at /usr/local/rvm/rubies/jruby-1.7.8/lib/ruby/1.9/tsort.rb:150
       each_strongly_connected_component at /usr/local/rvm/rubies/jruby-1.7.8/lib/ruby/1.9/tsort.rb:183
  each_strongly_connected_component_from at /usr/local/rvm/rubies/jruby-1.7.8/lib/ruby/1.9/tsort.rb:219
       each_strongly_connected_component at /usr/local/rvm/rubies/jruby-1.7.8/lib/ruby/1.9/tsort.rb:182
                                    each at org/jruby/RubyArray.java:1613
       each_strongly_connected_component at /usr/local/rvm/rubies/jruby-1.7.8/lib/ruby/1.9/tsort.rb:180
                              tsort_each at /usr/local/rvm/rubies/jruby-1.7.8/lib/ruby/1.9/tsort.rb:148
                        run_initializers at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/initializable.rb:54
                             initialize! at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/application.rb:215
                          method_missing at /srv/synchronicity/shared/bundle/jruby/1.9/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30
                                  (root) at /srv/synchronicity/releases/20131210000248/config/environment.rb:5
                                 require at org/jruby/RubyKernel.java:1084
                                  (root) at file:/srv/synchronicity/shared/bundle/jruby/1.9/gems/jruby-rack-1.1.13.3/lib/jruby-rack-1.1.13.3.jar!/jruby/rack/rails/environment3.rb:1
                        load_environment at file:/srv/synchronicity/shared/bundle/jruby/1.9/gems/jruby-rack-1.1.13.3/lib/jruby-rack-1.1.13.3.jar!/jruby/rack/rails/environment3.rb:25
                        load_environment at file:/srv/synchronicity/shared/bundle/jruby/1.9/gems/jruby-rack-1.1.13.3/lib/jruby-rack-1.1.13.3.jar!/jruby/rack/rails_booter.rb:79

--- RubyGems
Gem.dir: /srv/synchronicity/shared/bundle/jruby/1.9
Gem.path:
/srv/synchronicity/shared/bundle/jruby/1.9
Activated gems:
  rake-10.1.0
  i18n-0.6.9
  minitest-4.7.5
  multi_json-1.8.2
  atomic-1.1.14-java
  thread_safe-0.1.3-java
  tzinfo-0.3.38
  activesupport-4.0.2
  amq-protocol-1.9.0
  eventmachine-1.0.3-java
  amqp-1.1.3
  timers-1.1.0
  celluloid-0.15.2
  action_subscriber-0.1.10
  builder-3.1.4
  erubis-2.7.0
  rack-1.5.2
  rack-test-0.6.2
  actionpack-4.0.2
  mime-types-1.25.1
  polyglot-0.3.3
  treetop-1.4.15
  mail-2.5.4
  actionmailer-4.0.2
  activemodel-4.0.2
  active_attr-0.8.2
  thor-0.18.1
  protobuf-2.8.8
  active_remote-1.6.1
  will_paginate-3.0.5
  active_remote_pagination-0.3.2
  activerecord-deprecated_finders-1.0.3
  arel-4.0.1
  activerecord-4.0.2
  activerecord-jdbc-adapter-1.3.3
  jdbc-postgres-9.3.1100
  activerecord-jdbcpostgresql-adapter-1.3.3
  ffi-1.9.3-java
  ffi-rzmq-1.0.3
  guid-0.1.1
  atlas-1.6.5
  babou-0.2.2
  bundler-1.3.5
  heredity-0.1.1
  ignorable-0.2.0
  lumberjack-1.0.4
  lumberjack_syslog_device-1.0.0
  highline-1.6.20
  fattr-2.2.1
  options-2.3.0
  progress_bar-1.0.0
  safe_yaml-0.9.7
  json-1.8.1-java
  squash_ruby-1.2.2
  squash_rails-1.2.0
  sucker_punch-1.0.2
  buttress-2.1.12
  coderay-1.1.0
  connection_pool-1.1.0
  dotenv-0.9.0
  rufus-scheduler-3.0.2
  firebolt-0.12.0
  foreman-0.63.0-java
  hike-1.2.3
  jruby-rack-1.1.13.3
  urlcrypt-0.1.0
  warden-1.2.3
  lockout-2.2.5
  method_source-0.8.2
  minimus-0.2.1
  protected_attributes-1.0.5
  slop-3.4.7
  spoon-0.0.4
  pry-0.9.12.3-java
  pry-nav-0.2.3
  rack-strong_routes-0.0.7
  railties-4.0.2
  tilt-1.4.1
  sprockets-2.10.1
  sprockets-rails-2.0.1
  rails-4.0.2
  redis-3.0.6
  redis-store-1.1.4
  redis-rack-1.5.0
  redis-actionpack-4.0.0
  redis-activesupport-4.0.0
  redis-namespace-1.3.2
  redis-rails-4.0.0
  sidekiq-2.16.1
  trinidad_jars-1.2.5
  trinidad-1.4.5
  trinidad_dbpool-0.5.0
  trinidad_postgresql_dbpool_extension-0.5.0

Is this a known issue with Rails 4? I'm happy to come up with a minimal reproducible if this is unknown territory.

@kares
Copy link
Member

kares commented Dec 10, 2013

Thanks Michael, will look at this - likely to be fixed on AR-JDBC's side ... could we see your Gemfile ?
Also were you using Ar-JDBC 1.3.3 with 3.2 as well ?

@mmmries
Copy link
Author

mmmries commented Dec 10, 2013

Gemfile shown below. We were previously using AR-JDBC 1.2.9 with rails 3.2, but 1.2.9 is not compatible with Rails 4.

Here is the gemfile:

source 'http://gems.moneydesktop.com'
source 'https://rubygems.org'

# Rails and its supporting gems
gem 'rails', '4.0.2'

# Private gems (#mdtech represent!)
gem 'active_remote_pagination', '~> 0.3.0' # 0.4 added Celluloid, which doesn't work with Sync::Remote.
gem 'atlas'
gem 'babou'
gem 'buttress'
gem 'lockout'
gem 'minimus'
gem 'rack-strong_routes'

# Public gems
gem 'active_remote'
gem 'redis-rails'
gem 'protected_attributes'
gem 'safe_yaml'
gem 'sidekiq'

# JRuby-specific gems
platforms :jruby do
  gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
  gem 'json'

  # Use Trinidad as the app server
  gem 'trinidad'
  gem 'trinidad_postgresql_dbpool_extension'
end

# MRI-specific gems
platforms :ruby do
  gem 'pg'
  gem 'oj'

  # Use Unicorn as the app server
  gem 'unicorn'
end

# Deploy it with Trebuchet
gem 'trebuchet', :group => :development

# Get it running with Foreman
gem 'foreman', :require => false

# So we have it when we need it
gem 'pry-nav', :group => [ :development, :test, :sandbox, :qa ]

# Test it with RSpec
gem 'rspec-rails', :group => [ :development, :test ]

group :development do
  gem 'md-yard'
  gem 'thin', :platform => :ruby
end

group :test do
  gem 'factory_girl_rails'
  gem 'md_smoke', :require => 'smoke'
  gem 'protobuf-rspec'
  gem 'rspec-pride'
  gem 'shoulda'
  gem 'simplecov', :require => false
  gem 'testarossa'
  gem 'timecop'
end

@kares
Copy link
Member

kares commented Dec 10, 2013

you can confirm it's an AR-JDBC regression if you disable prepared_statements ... than it should simply work for now, actually should happen on 3.2 as well if you upgrade to 1.3.x

@mmmries
Copy link
Author

mmmries commented Dec 10, 2013

I set

prepared_statements: false

for both config/database.yml and in my trinidad.yml where I load the postgresql_dbpool extension, but I still get the same exception. Looks like in activerecord-jdbc-adapter 1.3.3 the call sight is in lib/arjdbc/postgresql/adapter.rb line 1102.

   def table_exists?(name)
      schema, table = extract_schema_and_table(name.to_s)
      return false unless table # abstract classes - nil table name

      binds = [[ nil, table.gsub(/(^"|"$)/,'') ]]
      binds << [ nil, schema ] if schema
      sql = <<-SQL
        SELECT COUNT(*) as table_count
        FROM pg_tables
        WHERE tablename = ?
        AND schemaname = #{schema ? "?" : "ANY (current_schemas(false))"}
      SQL

      log(sql, 'SCHEMA', binds) do
        @connection.execute_query_raw(sql, binds).first["table_count"] > 0
      end
    end

Calling execute_query_raw would seem like it is already bypassing the prepared statement stuff?

@kares
Copy link
Member

kares commented Dec 11, 2013

definitely an AR-JDBC issue ... should be fixed in next release please track at jruby/activerecord-jdbc-adapter#515 thx!

@kares kares closed this as completed Dec 11, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants