title: Rails, ActionController::Live, Puma: ThreadError
body: <p>I want to stream notification to the client. For this, I use Redis <code>pup/sub</code> and the <code>ActionController::Live</code>. Here is what my <code>StreamingController</code> looks like:</p>
  
  <pre><code>class StreamingController &lt; ActionController::Base
    include ActionController::Live
  
    def stream
      response.headers['Content-Type'] = 'text/event-stream'
  
      $redis.psubscribe("user-#{params[:user_id]}:*") do |on|
        on.pmessage do |subscription, event, data|
          response.stream.write "data: #{data}\n\n"
        end
      end
    rescue IOError
      logger.info "Stream closed"
    ensure
      response.stream.close
    end
  end
  </code></pre>
  
  <p>Here the JS part to listen to the stream:</p>
  
  <pre><code>var source = new EventSource("/stream?user_id=" + user_id);
  source.addEventListener("message", function(e) {
    data = jQuery.parseJSON(e.data);
  
    switch(data.type) {
      case "unread_receipts":
        updateUnreadReceipts(data);
        break;
    }
  }, false);
  </code></pre>
  
  <p>Now if I push something to redis, the client gets the push-notification. So this works fine. But when I click on a link nothing is happening. After canceling the rails server (I use puma) with <kbd>Ctrl</kbd>+<kbd>C</kbd> I got the following error:</p>
  
  <p><code>ThreadError: Attempt to unlock a mutex which is locked by another thread</code></p>
  
  <p>The problem can be solved after adding <code>config.middleware.delete Rack::Lock</code> to development.rb, but then I don't see any console output after pushing to the client. <code>config.cache_classes = true</code> and <code>config.eager_load = true</code>are no options because I don't want to restart my server every time in development.</p>
  
  <p>Is there any other solution?</p>