Closed jdelStrother closed 5 years ago
I'd like to hesitantly propose this as a fix...
diff --git a/lib/thinking_sphinx/configuration.rb b/lib/thinking_sphinx/configuration.rb
index 7ce15dd7..e983e8a5 100644
--- a/lib/thinking_sphinx/configuration.rb
+++ b/lib/thinking_sphinx/configuration.rb
@@ -10,7 +10,7 @@ class ThinkingSphinx::Configuration < Riddle::Configuration
delegate :environment, :to => :framework
- @@mutex = Mutex.new
+ @@mutex = ActiveSupport::Concurrency::LoadInterlockAwareMonitor.new
def initialize
super
Which appears to fix my deadlocks. I don't understand enough of AS::Dependencies' locking insanity to say for sure it's the correct fix, though.
I'm glad to know you've found a fix! And I'm a little surprised the issue you've hit hasn't been noted by anyone else… I've used Thinking Sphinx and Puma together in my apps, and I'm sure others have too. 🤔
I'll have a look into the ActiveSupport monitor class soon to confirm it's a good fit - but the fact it's working for you is a great sign.
I think the reason I'm consistently running into it is that we have a before_filter that creates an AuditLog activerecord object on every single request, and pages that fire multiple simultaneous ajax calls, so I'm probably doing more concurrent inserts than most people.
I've created a demo repository here - https://github.com/jdelStrother/thinkingsphinx-deadlock. The readme has instructions on reproducing the problem, but the money shot is here: https://github.com/jdelStrother/thinkingsphinx-deadlock/blob/master/app/controllers/application_controller.rb#L32. Let me know if I can do anything to help.
Just pushed a commit that should resolve this - essentially, your solution, but only when that ActiveSupport class is available (which seems to be from 5.1.5 onwards, for an issue that was introduced at some point in the 5.1.x releases). Thanks so much for the test app too, that was a great way to review the problem! 👏
This fix is available in the newly-released v4.3.0, with credit to you in the release notes/changelog 😄
I run multithreaded puma in development, and get fairly frequent deadlocks if two concurrent requests try to create a record.
The problem appears to be due to the mutex handling in
Configuration#preload_indices
:I hoped I could fix this by wrapping the mutex in
permit_concurrent_loads
, but that doesn't appear to help. Any other suggestions I might try?