Project

General

Profile

Actions

Bug #3126

closed

Cannot start a transaction within a transaction

Added by Pan Luo over 11 years ago. Updated about 11 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Rails
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

I'm using foreman 1.2.0 and from now and then I randomly got error message saying "We're sorry, but something went wrong." and in the log, I got

ActiveRecord::StatementInvalid (SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction):
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

It seems the db is locked up. Restart apache solves the problem. Wondering if it is a bug or I did something wrong?

Actions #1

Updated by Anonymous over 11 years ago

Could you provide the full backtrace please -- this snippet doesn't show the origin of the exception...

Actions #2

Updated by Pan Luo over 11 years ago

This is the full trace unless I need to turn on something.

Here is a few ones with context: ========================

ActiveRecord::StatementInvalid (SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction):
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

Started POST "/reports/create?format=yml" for 10.93.1.2 at 2013-09-19 02:57:10 -0700
Processing by ReportsController#create as YML
Parameters: {"report"=>"[FILTERED]"}
processing report for xxxx.xxxx.xxx.xx
Failed to process report for xxxx.xxxx.xxx.xx due to:SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction
Rendered text template (0.0ms)
Completed 500 Internal Server Error in 37ms (Views: 0.3ms | ActiveRecord: 0.9ms)

ActiveRecord::StatementInvalid (SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction):
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

Failed to process report for balancer due to:SQLite3::BusyException: database is locked: commit transaction
Rendered text template (0.0ms)
Completed 500 Internal Server Error in 5342ms (Views: 1.6ms | ActiveRecord: 5014.5ms)

ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked: commit transaction):
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

Started GET "/node/xxx1.xx.xx.xx?format=yml" for 10.93.1.2 at 2013-09-19 02:59:30 -0700
Processing by HostsController#externalNodes as YML
Parameters: {"name"=>"xxx1.xx.xx.xx"}
Rendered text template (0.0ms)
Completed 200 OK in 25ms (Views: 0.7ms | ActiveRecord: 3.7ms)

ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked: commit transaction):
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

========================

Actions #3

Updated by Ohad Levy over 11 years ago

  • Status changed from New to Feedback
  • Priority changed from High to Normal

this sounds like a limitation in sqlite, sqlite is not a full blown production database, and as such, it has limited ability to handle load, my assumption is that you have reached that, and its time to move to mysql or postgresql.

Actions #4

Updated by Pan Luo over 11 years ago

How much is the limitation? I only have around 20 hosts and I'm the only user on foreman..

I upgraded to 1.2.2. The problem seems disappeared. Though I didn't login for the past few days. I'll report back if it's back.

Actions #5

Updated by Pan Luo over 11 years ago

Issue still exists in 1.2.2. Just upgraded 1.3.1 last night and got the same issue this morning.

Started GET "/hosts" for xxx.xxx.xxx.xxx at 2013-12-04 11:29:38 -0800
Processing by HostsController#index as HTML
Session for Admin User is expired.
failed to determine if user sessions needs to be expired, expiring anyway: SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction
Session for Admin User is expired.
Operation FAILED: SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction
Rendered common/500.html.erb within layouts/application (5.7ms)
Completed 500 Internal Server Error in 41ms (Views: 33.7ms | ActiveRecord: 1.1ms)

ActiveRecord::StatementInvalid (SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction):
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

Actions #6

Updated by Lukas Zapletal over 11 years ago

It does not matter if you are the only one using Foreman or how many hosts you have. You are apparently using Passenger, have you configured to spawn only one instance of the application? You should do that, otherwise you will have locking or transaction issues. SQLite is fantastic database, but it is not meant for production use.

Although SQLite does support some kind of multiple readers one writers mechanisms, we are not testing this configuration and I'd recommend you to either make sure only one instance of the Foreman Rails app can be running by changing limits in the passenger configuration. Or I'd migrate to PostgreSQL database, we do support this without loosing your data using prod2dev tool: https://groups.google.com/forum/#!topic/foreman-users/oGWeXYMDf9c

Actions #7

Updated by Benjamin Papillon about 11 years ago

Hello,

Did you try Lukas suggestions? Can you provide us with feedback regarding this issue?

Thanks

Actions #8

Updated by Pan Luo about 11 years ago

Sorry, forgot it. I eventually switched to postgres from SQLite as Lukas suggested and the problem is gone.

Actions #9

Updated by Dominic Cleal about 11 years ago

  • Status changed from Feedback to Resolved

Thanks for confirming, glad you're up and running.

Actions

Also available in: Atom PDF