Skip to content

grape is not threadsafe #517

Closed
Closed
@bwalex

Description

@bwalex

When running grape on puma, all sorts of weirdness happens to the activerecord connection pool - things fail randomly and at times all the connections stay checked out, not leaving any connections in the pool.

The same code run on unicorn works just fine. It's worth noting that doing the same before/after thing with sinatra works fine on both puma and unicorn, so I think the problem is grape (rather than ActiveRecord or the DB driver).

Another odd thing happens when moving the 'after' block after the 'resource' block - then it is not run at all; but that's probably a separate issue.

class API < Grape::API
  version 'v1', using: :header, vendor: 'foobar'
  format :json
  prefix '/api'


  before do
    ActiveRecord::Base.connection_pool.connections.map(&:verify!)
  end

  after do
    ActiveRecord::Base.clear_active_connections!
  end


  resource :comments do
    ...
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions