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

ActiveRecord::ConnectionTimeoutError after 7 times reload page in development(0.12.3) #1749

Closed
grasp opened this Issue Aug 23, 2014 · 11 comments

Comments

Projects
None yet
5 participants
@grasp

grasp commented Aug 23, 2014

This issue not reproduced on padrino 0.12.2

it probably a bug only on 0.12.3

on padrino 0.12.3

when reload a page for about 7 times, there will pop up a error.
ActiveRecord::ConnectionTimeoutError

and it was say there are too much connection with database, only restart web server to work around.

two work around not work

I searched the Google , and found two work around, still not work.

Some guess

one possible , is padrino did not close database connection for each request ,
or
it did not load app.rb each time's request where it close the connection?

@namusyaka namusyaka added the bug label Aug 23, 2014

@namusyaka namusyaka added this to the 0.12.4 milestone Aug 23, 2014

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka Aug 23, 2014

Member

This problem occurs only when using the thin server and the threaded property is true.
Basically your after handling works but it does not work in error pages.

Member

namusyaka commented Aug 23, 2014

This problem occurs only when using the thin server and the threaded property is true.
Basically your after handling works but it does not work in error pages.

@namusyaka namusyaka added revalidate and removed bug labels Aug 23, 2014

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka Aug 23, 2014

Member

@grasp You can avoid this problem with simple middleware.

class ConnectionPoolWithConnection
  def initialize(app)
    @app = app
  end

  def call(env)
    ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
  end
end
# app/app.rb
class App < Padrino::Application
  use ConnectionPoolWithConnection

@padrino/core-members What do you think about this problem?

Member

namusyaka commented Aug 23, 2014

@grasp You can avoid this problem with simple middleware.

class ConnectionPoolWithConnection
  def initialize(app)
    @app = app
  end

  def call(env)
    ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
  end
end
# app/app.rb
class App < Padrino::Application
  use ConnectionPoolWithConnection

@padrino/core-members What do you think about this problem?

@ujifgc

This comment has been minimized.

Show comment
Hide comment
@ujifgc

ujifgc Aug 23, 2014

Member

If it's necessary to dance around ActiveRecord's connection pool then it might be worth adding to the project generator.

Member

ujifgc commented Aug 23, 2014

If it's necessary to dance around ActiveRecord's connection pool then it might be worth adding to the project generator.

@ujifgc

This comment has been minimized.

Show comment
Hide comment
@ujifgc

ujifgc Aug 23, 2014

Member

If it's there then why is it not working?

Member

ujifgc commented Aug 23, 2014

If it's there then why is it not working?

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka Aug 23, 2014

Member

I don't know.
I wanted to know whether my suggestion's code should be placed near there.

Member

namusyaka commented Aug 23, 2014

I don't know.
I wanted to know whether my suggestion's code should be placed near there.

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka Aug 23, 2014

Member

Is it possible that this https://github.com/rails/rails/blob/dfeeecd2f3bde70f22174843ccfc594610b4eebc/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L637-L655 is broken and won't work in threaded environment?

Yes, it doesn't work, but I'm not sure whether the middleware should work in threaded environment.

As for https://github.com/rails/rails/blob/dfeeecd2f3bde70f22174843ccfc594610b4eebc/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L45-L47 your code should be right for the situation.

I'm worried that my middleware is generated even if thin server isn't used.

Member

namusyaka commented Aug 23, 2014

Is it possible that this https://github.com/rails/rails/blob/dfeeecd2f3bde70f22174843ccfc594610b4eebc/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L637-L655 is broken and won't work in threaded environment?

Yes, it doesn't work, but I'm not sure whether the middleware should work in threaded environment.

As for https://github.com/rails/rails/blob/dfeeecd2f3bde70f22174843ccfc594610b4eebc/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L45-L47 your code should be right for the situation.

I'm worried that my middleware is generated even if thin server isn't used.

@ujifgc

This comment has been minimized.

Show comment
Hide comment
@ujifgc

ujifgc Sep 5, 2014

Member

The issue can be reproduced on any version and is not related to Padrino.

Member

ujifgc commented Sep 5, 2014

The issue can be reproduced on any version and is not related to Padrino.

@ujifgc ujifgc closed this Sep 5, 2014

@ujifgc ujifgc added wontfix and removed revalidate labels Sep 5, 2014

ujifgc added a commit that referenced this issue Sep 6, 2014

Merge pull request #1750 from padrino/connection-pool-with-thin
Add ConnectionPoolWithConnection as middleware to application if ActiveRecord and thin are used, fixes #1749

@ujifgc ujifgc removed the wontfix label Sep 6, 2014

@Rendez

This comment has been minimized.

Show comment
Hide comment
@Rendez

Rendez Sep 17, 2014

Guys, I've spend several hours fighting with my implementation and config. with exactly the same issue! Just two days ago I switched to from Puma to Thin. Back to Puma, I am going to use thread count.

Thanks a lot for the research and the feedback!

Rendez commented Sep 17, 2014

Guys, I've spend several hours fighting with my implementation and config. with exactly the same issue! Just two days ago I switched to from Puma to Thin. Back to Puma, I am going to use thread count.

Thanks a lot for the research and the feedback!

@hernanvicente

This comment has been minimized.

Show comment
Hide comment
@hernanvicente

hernanvicente Dec 8, 2014

I had the same problem. Thanks @Rendez your solution saved me a lot of time.
I was using padrino 0.12.4 with thin (1.6.3). I switched to puma (2.10.2)

hernanvicente commented Dec 8, 2014

I had the same problem. Thanks @Rendez your solution saved me a lot of time.
I was using padrino 0.12.4 with thin (1.6.3). I switched to puma (2.10.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment