-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 5.0.1, 5.0.2
-
Component/s: None
-
Labels:None
-
Environment:ubuntu 14.04, ruby 2.2.4, rails 4.2.5, rainbows 5(4 threads per worker)
mongodb replset, 3 nodes, 1 primary, 2 secondary, read_mode: secondary_preferred, auth_meth: scram.
Sorry for my English, hope you guys can get it. Thanks in advanced.
Mongoid 5.0 makes chaos and confusion in my environment. I think it's a very big problem, cause it makes my rails application stop working. I don't know if i'm the only one who met this kind of problem. I had to downgrade to mongoid 4 finally, version 4 is good.
It happens occasionally, and if I restart my rails web application, it disappears, but re-appear after about half an hour. But if I run the sentense in rails console many times, no problem appears.
The problem is: some instances will be wrong, i visit the same page, a certain of instance of this page is good in most of time, but sometimes it is nil, or even another kind of instance. it is most weird.
For example, No. 1:
FollowLecturerMongo.where(:is_valid => true).distinct(:user_id).count
It should return a number, or 0, isn't it? but sometimes it throw the exception: "undefined method `count' for nil:NilClass". FollowLecturerMongo.where(...).distinct(...) should always be an array, I think, but return nil? don't know why.
Example No. 2:
StockStyleMongo.limit(8).each
{|ss| ss.name}Sometimes it throw the exception: "undefined method `name' for #<WxScanMessageMongo:0x007fc9c865cc48>"
The instance 'ss' in the block should be a instance of class StockStyleMongo, but, "WxScanMessageMongo"? the latter class is never been used in this page!
Example No. 3:
Log::SmsStatusMongo.create(id_code: id_code)
Sometimes it throws "undefined method `[]' for nil:NilClass" in the stack:
mongo-2.2.1/lib/mongo/operation/commands/find/result.rb:46:in `documents'
mongo-2.2.1/lib/mongo/cursor.rb:201:in `process'
mongo-2.2.1/lib/mongo/cursor.rb:85:in `each'
mongo-2.2.1/lib/mongo/collection/view/iterable.rb:44:in `each'
mongoid-5.0.2/lib/mongoid/query_cache.rb:207:in `each'
mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:148:in `first'
mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:148:in `block in exists?'
mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:488:in `try_cache'
mongoid-5.0.2/lib/mongoid/contextual/mongo.rb:147:in `exists?'
mongoid-5.0.2/lib/mongoid/contextual.rb:20:in `exists?'
mongoid-5.0.2/lib/mongoid/validatable/uniqueness.rb:277:in `validate_root'
mongoid-5.0.2/lib/mongoid/validatable/uniqueness.rb:48:in `block in validate_each'
mongoid-5.0.2/lib/mongoid/validatable/queryable.rb:23:in `with_query'
mongoid-5.0.2/lib/mongoid/validatable/uniqueness.rb:42:in `validate_each'
activemodel-4.2.5/lib/active_model/validator.rb:151:in `block in validate'
......
mongo-2.2.1/lib/mongo/operation/commands/find/result.rb:46, that's the statement:
cursor_document[FIRST_BATCH]
the cursor_document is nil? is it possible?
============================
Conclusion:
It seems that sometimes mongoid 5 makes chaos, return wrong instance or return nil what's impossible. Maybe something wrong in the connection_pool integrated in mongoid 5? Call mongodb via one connection_pool, get the result through another one? But I tried limiting the max_pool_size to 1, exception still happened. I limited rainbows thread to 1, or changed rainbows to unicorn, problem still appeared.
There's no problem when I run the above statements in rails console, no matter how many times I run it. The problems just appear when I visit the web page. Hope it's helpful for you.
Thanks for your patient, hope this bug would be fixed soon. I'll be back to mongoid 5. Thank you all.