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

SQLite3::BusyException: database is locked #84

Closed
szymon-przybyl opened this issue Jun 5, 2011 · 7 comments
Closed

SQLite3::BusyException: database is locked #84

szymon-przybyl opened this issue Jun 5, 2011 · 7 comments

Comments

@szymon-przybyl
Copy link

I have the following error while running some spec, which is using machinist's make!:
SQLite3::BusyException: database is locked

I have simply one blueprint, and when trying to make that blueprint, error as above is being displayed when running rake spec.

@notahat
Copy link
Owner

notahat commented Jun 6, 2011

Without runnable code, I can't duplicate the problem.

@notahat notahat closed this as completed Jun 6, 2011
@borisd
Copy link

borisd commented Jun 22, 2011

Same problem (also see http://stackoverflow.com/questions/78801/sqlite3busyexception)

blueprints.rb

require 'machinist/active_record'

User.blueprint do
name { "User_#{sn}" }
email { "#{object.name}@email.com" }
password { '123123'}
end

user.rb

class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "is invalid") unless
value =~ /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i
end
end

class User < ActiveRecord::Base
attr_accessible :email, :password, :name

attr_accessor :password
before_save :encrypt_password

validates :email,
:presence => true,
:uniqueness => true,
:email => true

validates :password,
:presence => true,
:length => { :within => 5..40 },
:on => :create

def encrypt_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = User::encrypted_password(password, password_salt)
end
end

def self.encrypted_password(password, password_salt)
BCrypt::Engine.hash_secret(password, password_salt)
end
end

@notahat
Copy link
Owner

notahat commented Jun 22, 2011

I can't reproduce the issue from that. (At the very least I need code packaged up so I can run it, and the steps needed to trigger the problem.)

Odds are this isn't a Machinist issue. The error is SQLite complaining about concurrent requests, and Machinist just makes regular ActiveRecord calls under the hood.

@cice
Copy link

cice commented Jun 30, 2011

the problem lies with transactional fixtures, cause
https://github.com/notahat/machinist/blob/v2.0.0.beta2/lib/machinist/shop.rb#L43
tries create object outside the transaction in another thread,
this is just a caching mechanism, right? maybe it could be deactivated when transactional_fixtures are enabled

@cice
Copy link

cice commented Jun 30, 2011

ok, just saw that there is a simple option to disable caching, works perfectly fine now

Machinist.configure do |config|
  config.cache_objects = false
end

@notahat
Copy link
Owner

notahat commented Jul 1, 2011

Caching has been removed from the edge version of Machinist.

@emk
Copy link

emk commented Jul 1, 2011

Machinist::ActiveRecord::Blueprint.outside_transaction was creating a second thread and opening up a new connection to SQLite3. This seemed to fail while another transaction was already running in the primary thread. What's odd is that it did work sometimes, but not reliably. I'm guessing that opening up multiple SQLite3 connections through the latest ActiveRecord is just not reliable.

Switching to edge fixed the problem for me.

Thank you for all your work on an excellent library!

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

5 participants