-
Notifications
You must be signed in to change notification settings - Fork 87
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
Error "undefined method 'first' for nil:NilClass (NoMethodError)" probaby caused by concurecy #257
Comments
Hey, I'll have a look at that In the backend feature matrix we have the Sqlite adapter listed as having unknown thread safety. From looking back through the code history, the reason for this is unclear, but it looks like this is because either the sqlite3 database itself was not good at concurrency at the time (which might be outdated), or because of issues with the ruby gem. There's some discussion of GVL/threading issues here: sparklemotion/sqlite3-ruby#287 (comment). That discussion also points to https://www.sqlite.org/threadsafe.html which explains that the sqlite C library may be compiled in various ways wrt threadsafety, so you might want to double-check that The two alternative approaches suggested in that thread (separate connections for separate threads, or using a mutex) are both doable in Moneta. The You might want to try these two approaches to see if they help at all: store_with_pool = Moneta.build do
# if you're switching from `Moneta.new` to `Moneta.build`, add this for compatibility
use :Transformer, key: :marshal, value: :marshal
# there are a bunch of options you can use with `:Pool` to control how many connections there are
use :Pool max: 4 do
adapter :Sqlite, file: 'my.db'
end
end
store_with_mutex = Moneta.new(:Sqlite, file: 'my.db', threadsafe: true)
# equivalent to:
store_with_mutex = Moneta.build do
use :Transformer, key: :marshal, value: :marshal
use :Lock
adapter :Sqlite, file: 'my.db'
end |
Thank you for the detailed response! |
After one month of testing, I can say that |
In lib/moneta/adapters/sqlite.rb:57 there is a block
and several times I got this strange error:
undefined method 'first' for nil:NilClass (NoMethodError)
In my case, simple retry after a small delay worked, but there may be a better solution.
I think it is somehow caused by doing this operation from parallel threads.
The text was updated successfully, but these errors were encountered: