Skip to content

Commit

Permalink
Addresses memory issues related to new multi-instance approach (#1836)
Browse files Browse the repository at this point in the history
  • Loading branch information
myxoh authored and dblock committed Dec 6, 2018
1 parent 7413b7e commit aabb722
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### Fixes

* Your contribution here.
* [#1836](https://github.com/ruby-grape/grape/pull/1836): Fix: memory leak not releasing `call` method calls from setup - [@myxoh](https://github.com/myxoh).
* [#1830](https://github.com/ruby-grape/grape/pull/1830), [#1829](https://github.com/ruby-grape/grape/issues/1829): Restores `self` sanity - [@myxoh](https://github.com/myxoh).

### 1.2.1 (2018/11/28)
Expand Down
11 changes: 10 additions & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Grape
# should subclass this class in order to build an API.
class API
# Class methods that we want to call on the API rather than on the API object
NON_OVERRIDABLE = Class.new.methods.freeze
NON_OVERRIDABLE = Class.new.methods.freeze + %i[call call!]

class << self
attr_accessor :base_instance, :instances
Expand Down Expand Up @@ -42,6 +42,15 @@ def override_all_methods!
end
end

# This is the interface point between Rack and Grape; it accepts a request
# from Rack and ultimately returns an array of three values: the status,
# the headers, and the body. See [the rack specification]
# (http://www.rubydoc.info/github/rack/rack/master/file/SPEC) for more.
# NOTE: This will only be called on an API directly mounted on RACK
def call(*args, &block)
base_instance.call(*args, &block)
end

# Allows an API to itself be inheritable:
def make_inheritable(api)
# When a child API inherits from a parent API.
Expand Down
9 changes: 9 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ def app
end
end

describe '.call' do
context 'it does not add to the app setup' do
it 'calls the app' do
expect(subject).not_to receive(:add_setup)
subject.call({})
end
end
end

describe '.route_param' do
it 'adds a parameterized route segment namespace' do
subject.namespace :users do
Expand Down

0 comments on commit aabb722

Please sign in to comment.