Skip to content

Commit 70db3f7

Browse files
committed
Merge pull request #585 from SPBTV/thread-safety
Fix after boot thread-safety issue
2 parents 4665792 + 16e45c8 commit 70db3f7

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Next Release
3131
* [#538](https://github.com/intridea/grape/pull/538): Fixed default values for grouped params - [@dm1try](https://github.com/dm1try).
3232
* [#549](https://github.com/intridea/grape/pull/549): Fixed handling of invalid version headers to return 406 if a header cannot be parsed - [@bwalex](https://github.com/bwalex).
3333
* [#557](https://github.com/intridea/grape/pull/557): Pass `content_types` option to `Grape::Middleware::Error` to fix the content-type header for custom formats. - [@bernd](https://github.com/bernd).
34-
34+
* [#585](https://github.com/intridea/grape/pull/585): Fix after boot thread-safety issue - [@etehtsea](https://github.com/etehtsea).
3535

3636
0.6.1 (10/19/2013)
3737
==================

lib/grape.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require 'multi_xml'
1818
require 'virtus'
1919
require 'i18n'
20+
require 'thread'
2021

2122
I18n.load_path << File.expand_path('../grape/locale/en.yml', __FILE__)
2223

lib/grape/api.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class << self
99
attr_reader :endpoints, :instance, :routes, :route_set, :settings, :versions
1010
attr_writer :logger
1111

12+
LOCK = Mutex.new
13+
1214
def logger(logger = nil)
1315
if logger
1416
@logger = logger
@@ -26,15 +28,15 @@ def reset!
2628
end
2729

2830
def compile
29-
@instance = new
31+
@instance ||= new
3032
end
3133

3234
def change!
3335
@instance = nil
3436
end
3537

3638
def call(env)
37-
compile unless instance
39+
LOCK.synchronize { compile } unless instance
3840
call!(env)
3941
end
4042

0 commit comments

Comments
 (0)