Skip to content

Commit aabb722

Browse files
myxohdblock
authored andcommitted
Addresses memory issues related to new multi-instance approach (#1836)
1 parent 7413b7e commit aabb722

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#### Fixes
1010

1111
* Your contribution here.
12+
* [#1836](https://github.com/ruby-grape/grape/pull/1836): Fix: memory leak not releasing `call` method calls from setup - [@myxoh](https://github.com/myxoh).
1213
* [#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).
1314

1415
### 1.2.1 (2018/11/28)

lib/grape/api.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Grape
66
# should subclass this class in order to build an API.
77
class API
88
# Class methods that we want to call on the API rather than on the API object
9-
NON_OVERRIDABLE = Class.new.methods.freeze
9+
NON_OVERRIDABLE = Class.new.methods.freeze + %i[call call!]
1010

1111
class << self
1212
attr_accessor :base_instance, :instances
@@ -42,6 +42,15 @@ def override_all_methods!
4242
end
4343
end
4444

45+
# This is the interface point between Rack and Grape; it accepts a request
46+
# from Rack and ultimately returns an array of three values: the status,
47+
# the headers, and the body. See [the rack specification]
48+
# (http://www.rubydoc.info/github/rack/rack/master/file/SPEC) for more.
49+
# NOTE: This will only be called on an API directly mounted on RACK
50+
def call(*args, &block)
51+
base_instance.call(*args, &block)
52+
end
53+
4554
# Allows an API to itself be inheritable:
4655
def make_inheritable(api)
4756
# When a child API inherits from a parent API.

spec/grape/api_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ def app
220220
end
221221
end
222222

223+
describe '.call' do
224+
context 'it does not add to the app setup' do
225+
it 'calls the app' do
226+
expect(subject).not_to receive(:add_setup)
227+
subject.call({})
228+
end
229+
end
230+
end
231+
223232
describe '.route_param' do
224233
it 'adds a parameterized route segment namespace' do
225234
subject.namespace :users do

0 commit comments

Comments
 (0)