passenger 5.2.3 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +13 -0
  3. data/CONTRIBUTORS +5 -1
  4. data/build/agent.rb +22 -2
  5. data/build/cxx_tests.rb +41 -5
  6. data/build/misc.rb +4 -1
  7. data/build/support/cxx_dependency_map.rb +1746 -908
  8. data/build/support/vendor/cxx_hinted_parser/CxxHintedParser.sublime-project +8 -0
  9. data/build/support/vendor/cxx_hinted_parser/Gemfile +5 -0
  10. data/build/support/vendor/cxx_hinted_parser/Gemfile.lock +30 -0
  11. data/{src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core → build/support/vendor/cxx_hinted_parser}/LICENSE.md +1 -1
  12. data/build/support/vendor/cxx_hinted_parser/README.md +95 -0
  13. data/build/support/vendor/cxx_hinted_parser/Rakefile +4 -0
  14. data/{src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/initialize.rb → build/support/vendor/cxx_hinted_parser/lib/cxx_hinted_parser.rb} +2 -9
  15. data/build/support/vendor/cxx_hinted_parser/lib/cxx_hinted_parser/parser.rb +239 -0
  16. data/dev/ci/README.md +15 -2
  17. data/dev/ci/lib/set-container-envvars.sh +6 -0
  18. data/dev/ci/lib/setup-container.sh +4 -1
  19. data/dev/ci/scripts/debug-console-wrapper.sh +3 -1
  20. data/dev/ci/setup-host +5 -0
  21. data/dev/ci/tests/binaries/Jenkinsfile +105 -0
  22. data/dev/ci/tests/binaries/build-linux +38 -0
  23. data/dev/ci/tests/binaries/build-macos +40 -0
  24. data/dev/ci/tests/binaries/prepare-macos +38 -0
  25. data/dev/ci/tests/binaries/test-linux +45 -0
  26. data/dev/ci/tests/binaries/test-macos +38 -0
  27. data/dev/ci/tests/debian/Jenkinsfile +2 -2
  28. data/dev/ci/tests/rpm/Jenkinsfile +1 -1
  29. data/dev/configkit-schemas/index.json +3 -24
  30. data/dev/vagrant/nginx_rakefile +0 -1
  31. data/package.json +15 -5
  32. data/resources/templates/error_renderer/.editorconfig +19 -0
  33. data/resources/templates/error_renderer/with_details/README.md +9 -0
  34. data/resources/templates/error_renderer/with_details/dist/bundle.js +33 -0
  35. data/resources/templates/error_renderer/with_details/dist/styles.css +17 -0
  36. data/resources/templates/error_renderer/with_details/src/DetailsView.jsx +52 -0
  37. data/resources/templates/error_renderer/with_details/src/GetHelpView.jsx +61 -0
  38. data/resources/templates/error_renderer/with_details/src/JourneyView.css +50 -0
  39. data/resources/templates/error_renderer/with_details/src/JourneyView.jsx +621 -0
  40. data/resources/templates/error_renderer/with_details/src/PageMain.css +114 -0
  41. data/resources/templates/error_renderer/with_details/src/PageMain.jsx +136 -0
  42. data/resources/templates/error_renderer/with_details/src/ProblemDescriptionView.jsx +14 -0
  43. data/resources/templates/error_renderer/with_details/src/ProcessDetailsView.jsx +56 -0
  44. data/resources/templates/error_renderer/with_details/src/SolutionDescriptionView.css +5 -0
  45. data/resources/templates/error_renderer/with_details/src/SolutionDescriptionView.jsx +15 -0
  46. data/resources/templates/error_renderer/with_details/src/SummaryView.jsx +35 -0
  47. data/resources/templates/error_renderer/with_details/src/SystemComponentView.css +34 -0
  48. data/resources/templates/error_renderer/with_details/src/SystemComponentView.jsx +168 -0
  49. data/resources/templates/error_renderer/with_details/src/SystemComponentsView.css +13 -0
  50. data/resources/templates/error_renderer/with_details/src/SystemComponentsView.jsx +116 -0
  51. data/resources/templates/error_renderer/with_details/src/Tab.jsx +12 -0
  52. data/resources/templates/error_renderer/with_details/src/Tabs.jsx +104 -0
  53. data/resources/templates/error_renderer/with_details/src/bootstrap/bootstrap.css +3446 -0
  54. data/resources/templates/error_renderer/with_details/src/bootstrap/bootstrap.js +293 -0
  55. data/resources/templates/error_renderer/with_details/src/bootstrap/config.json +401 -0
  56. data/resources/templates/error_renderer/with_details/src/index.html.template +22 -0
  57. data/resources/templates/error_renderer/with_details/src/index.jsx +23 -0
  58. data/resources/templates/error_renderer/with_details/webpack.config.js +47 -0
  59. data/resources/templates/error_renderer/without_details/dist/bundle.js +1 -0
  60. data/resources/templates/error_renderer/without_details/dist/styles.css +1 -0
  61. data/resources/templates/{undisclosed_error.html.template → error_renderer/without_details/src/index.html.template} +7 -11
  62. data/resources/templates/error_renderer/without_details/src/index.js +1 -0
  63. data/resources/templates/{error_layout.css → error_renderer/without_details/src/main.css} +5 -2
  64. data/resources/templates/error_renderer/without_details/webpack.config.js +42 -0
  65. data/src/agent/AgentMain.cpp +3 -3
  66. data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +13 -0
  67. data/src/agent/Core/ApplicationPool/Common.h +3 -4
  68. data/src/agent/Core/ApplicationPool/Context.h +27 -17
  69. data/src/agent/Core/ApplicationPool/Group.h +3 -1
  70. data/src/agent/Core/ApplicationPool/Group/InitializationAndShutdown.cpp +2 -12
  71. data/src/agent/Core/ApplicationPool/Group/InternalUtils.cpp +55 -10
  72. data/src/agent/Core/ApplicationPool/Group/LifetimeAndBasics.cpp +1 -1
  73. data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
  74. data/src/agent/Core/ApplicationPool/Group/SpawningAndRestarting.cpp +13 -6
  75. data/src/agent/Core/ApplicationPool/Implementation.cpp +16 -100
  76. data/src/agent/Core/ApplicationPool/Options.h +8 -65
  77. data/src/agent/Core/ApplicationPool/Pool.h +4 -21
  78. data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +1 -60
  79. data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +10 -13
  80. data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +3 -8
  81. data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +2 -34
  82. data/src/agent/Core/ApplicationPool/Pool/StateInspection.cpp +1 -1
  83. data/src/agent/Core/ApplicationPool/Process.cpp +17 -12
  84. data/src/agent/Core/ApplicationPool/Process.h +146 -93
  85. data/src/agent/Core/ApplicationPool/Session.h +2 -2
  86. data/src/agent/Core/ApplicationPool/Socket.h +28 -27
  87. data/src/agent/Core/Config.h +1 -3
  88. data/src/agent/Core/ConfigChange.cpp +2 -4
  89. data/src/agent/Core/Controller.h +2 -8
  90. data/src/agent/Core/Controller/BufferBody.cpp +0 -2
  91. data/src/agent/Core/Controller/CheckoutSession.cpp +12 -24
  92. data/src/agent/Core/Controller/Config.h +1 -9
  93. data/src/agent/Core/Controller/ForwardResponse.cpp +0 -34
  94. data/src/agent/Core/Controller/Hooks.cpp +0 -7
  95. data/src/agent/Core/Controller/InitRequest.cpp +0 -43
  96. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +0 -4
  97. data/src/agent/Core/Controller/Request.h +1 -35
  98. data/src/agent/Core/Controller/SendRequest.cpp +0 -32
  99. data/src/agent/Core/CoreMain.cpp +19 -32
  100. data/src/agent/Core/SpawningKit/Config.h +329 -55
  101. data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h +369 -0
  102. data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h.cxxcodebuilder +307 -0
  103. data/src/agent/Core/SpawningKit/Context.h +211 -0
  104. data/src/agent/Core/SpawningKit/DirectSpawner.h +112 -122
  105. data/src/agent/Core/SpawningKit/DummySpawner.h +59 -20
  106. data/src/agent/Core/SpawningKit/ErrorRenderer.h +117 -0
  107. data/src/agent/Core/SpawningKit/Exceptions.h +1157 -0
  108. data/src/agent/Core/SpawningKit/Factory.h +24 -17
  109. data/src/agent/Core/SpawningKit/{BackgroundIOCapturer.h → Handshake/BackgroundIOCapturer.h} +48 -18
  110. data/src/agent/Core/SpawningKit/Handshake/Perform.h +1650 -0
  111. data/src/agent/Core/SpawningKit/Handshake/Prepare.h +582 -0
  112. data/src/agent/Core/SpawningKit/Handshake/Session.h +91 -0
  113. data/src/agent/Core/SpawningKit/Handshake/WorkDir.h +100 -0
  114. data/src/agent/Core/SpawningKit/Journey.h +561 -0
  115. data/src/agent/Core/SpawningKit/PipeWatcher.h +41 -18
  116. data/src/agent/Core/SpawningKit/README.md +534 -0
  117. data/src/agent/Core/SpawningKit/Result.h +182 -7
  118. data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h +69 -0
  119. data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h.cxxcodebuilder +110 -0
  120. data/src/agent/Core/SpawningKit/SmartSpawner.h +1027 -562
  121. data/src/agent/Core/SpawningKit/Spawner.h +70 -1134
  122. data/src/agent/Core/SpawningKit/UserSwitchingRules.h +3 -33
  123. data/src/agent/README.md +2 -3
  124. data/src/agent/Shared/ApiServerUtils.h +2 -3
  125. data/src/agent/SpawnEnvSetupper/SpawnEnvSetupperMain.cpp +932 -0
  126. data/src/agent/Watchdog/Config.h +1 -3
  127. data/src/agent/Watchdog/WatchdogMain.cpp +2 -1
  128. data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp +5 -0
  129. data/src/apache2_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.cpp +5 -0
  130. data/src/apache2_module/ConfigGeneral/ManifestGeneration.h +22 -13
  131. data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp +5 -0
  132. data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp +3 -0
  133. data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp +13 -0
  134. data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp +7 -0
  135. data/src/apache2_module/DirConfig/AutoGeneratedStruct.h +13 -0
  136. data/src/cxx_supportlib/Constants.h +3 -1
  137. data/src/cxx_supportlib/Exceptions.h +0 -121
  138. data/src/cxx_supportlib/LoggingKit/Implementation.cpp +7 -6
  139. data/src/cxx_supportlib/LoggingKit/Logging.h +3 -1
  140. data/src/cxx_supportlib/Utils.cpp +42 -0
  141. data/src/cxx_supportlib/Utils.h +7 -0
  142. data/src/cxx_supportlib/Utils/IOUtils.cpp +58 -0
  143. data/src/cxx_supportlib/Utils/IOUtils.h +13 -0
  144. data/src/cxx_supportlib/Utils/JsonUtils.h +130 -23
  145. data/src/cxx_supportlib/Utils/ScopeGuard.h +9 -4
  146. data/src/cxx_supportlib/Utils/StrIntUtils.cpp +7 -0
  147. data/src/cxx_supportlib/Utils/StrIntUtils.h +1 -0
  148. data/src/cxx_supportlib/Utils/SystemTime.h +1 -1
  149. data/src/cxx_supportlib/Utils/Timer.h +1 -1
  150. data/src/cxx_supportlib/WebSocketCommandReverseServer.h +6 -4
  151. data/src/cxx_supportlib/vendor-copy/adhoc_lve.h +1 -0
  152. data/src/helper-scripts/node-loader.js +54 -59
  153. data/src/helper-scripts/rack-loader.rb +63 -60
  154. data/src/helper-scripts/rack-preloader.rb +125 -72
  155. data/src/helper-scripts/wsgi-loader.py +100 -43
  156. data/src/nginx_module/ConfigGeneral/AutoGeneratedDefinitions.c +120 -112
  157. data/src/nginx_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.c +15 -8
  158. data/src/nginx_module/ConfigGeneral/AutoGeneratedSetterFuncs.c +142 -142
  159. data/src/nginx_module/ConfigGeneral/ManifestGeneration.c +26 -15
  160. data/src/nginx_module/ConfigGeneral/ManifestGeneration.h +3 -0
  161. data/src/nginx_module/LocationConfig/AutoGeneratedCreateFunction.c +76 -70
  162. data/src/nginx_module/LocationConfig/AutoGeneratedHeaderSerialization.c +114 -99
  163. data/src/nginx_module/LocationConfig/AutoGeneratedManifestGeneration.c +170 -156
  164. data/src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c +38 -35
  165. data/src/nginx_module/LocationConfig/AutoGeneratedStruct.h +5 -1
  166. data/src/ruby_supportlib/phusion_passenger.rb +5 -5
  167. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +14 -1
  168. data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
  169. data/src/ruby_supportlib/phusion_passenger/common_library.rb +0 -3
  170. data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +0 -1
  171. data/src/ruby_supportlib/phusion_passenger/constants.rb +2 -0
  172. data/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +646 -238
  173. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +117 -95
  174. data/src/ruby_supportlib/phusion_passenger/packaging.rb +0 -1
  175. data/src/ruby_supportlib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +5 -1
  176. data/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb +92 -69
  177. data/src/ruby_supportlib/phusion_passenger/public_api.rb +0 -17
  178. data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +0 -3
  179. data/src/ruby_supportlib/phusion_passenger/request_handler.rb +4 -5
  180. data/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb +0 -22
  181. metadata +64 -67
  182. data/resources/templates/error_layout.html.template +0 -86
  183. data/resources/templates/general_error.html.template +0 -1
  184. data/resources/templates/general_error_with_html.html.template +0 -1
  185. data/src/agent/Core/ApplicationPool/ErrorRenderer.h +0 -131
  186. data/src/agent/Core/SpawningKit/Options.h +0 -41
  187. data/src/agent/Core/UnionStation/Connection.h +0 -173
  188. data/src/agent/Core/UnionStation/Context.h +0 -536
  189. data/src/agent/Core/UnionStation/StopwatchLog.h +0 -147
  190. data/src/agent/Core/UnionStation/Transaction.h +0 -249
  191. data/src/agent/SpawnPreparer/SpawnPreparerMain.cpp +0 -208
  192. data/src/cxx_supportlib/UnionStationFilterSupport.cpp +0 -67
  193. data/src/cxx_supportlib/UnionStationFilterSupport.h +0 -1622
  194. data/src/nodejs_supportlib/phusion_passenger/log_express.js +0 -106
  195. data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +0 -202
  196. data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +0 -227
  197. data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +0 -448
  198. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/CONFIG.md +0 -37
  199. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Gemfile +0 -17
  200. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Gemfile.lock +0 -59
  201. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README-API.md +0 -5
  202. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +0 -117
  203. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +0 -115
  204. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +0 -423
  205. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +0 -238
  206. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/connection.rb +0 -67
  207. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +0 -281
  208. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/lock.rb +0 -62
  209. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/log.rb +0 -66
  210. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/message_channel.rb +0 -157
  211. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +0 -150
  212. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +0 -199
  213. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/controllers.rb +0 -187
  214. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/misc.rb +0 -303
  215. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/view_rendering.rb +0 -91
  216. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +0 -396
  217. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/spec_helper.rb +0 -279
  218. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/time_point.rb +0 -39
  219. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +0 -173
  220. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +0 -177
  221. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version.rb +0 -32
  222. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +0 -44
  223. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +0 -16
  224. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +0 -20
  225. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +0 -18
  226. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/union_station_hooks_core.gemspec +0 -23
  227. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +0 -14
  228. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +0 -45
  229. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/LICENSE.md +0 -19
  230. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +0 -104
  231. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Rakefile +0 -160
  232. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +0 -200
  233. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/action_controller_extension.rb +0 -45
  234. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/action_view_subscriber.rb +0 -55
  235. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_record_subscriber.rb +0 -41
  236. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_benchmarkable_extension.rb +0 -47
  237. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +0 -79
  238. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/exception_logger.rb +0 -57
  239. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version.rb +0 -32
  240. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +0 -44
  241. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +0 -34
@@ -1,238 +0,0 @@
1
- # Union Station - https://www.unionstationapp.com/
2
- # Copyright (c) 2010-2015 Phusion Holding B.V.
3
- #
4
- # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- UnionStationHooks.require_lib 'utils'
25
- UnionStationHooks.require_lib 'time_point'
26
- UnionStationHooks.require_lib 'request_reporter'
27
-
28
- module UnionStationHooks
29
- class << self
30
- # @note You do not have to call this! Passenger automatically calls
31
- # this for you! Just obtain the RequestReporter object that has been made
32
- # available for you.
33
- #
34
- # Indicates that a Rack request has begun. Given a Rack environment hash,
35
- # this method returns {RequestReporter} object, which you can use for
36
- # logging Union Station information about this request. This method should
37
- # be called as early as possible during a request, before any processing
38
- # has begun. Only after calling this method will it be possible to log
39
- # request-specific information to Union Station.
40
- #
41
- # The {RequestReporter} object that this method creates is also made
42
- # available through the `union_station_hooks` key in the Rack environment
43
- # hash, as well as the `:union_station_hooks` key in the current thread's
44
- # object:
45
- #
46
- # env['union_station_hooks']
47
- # # => RequestReporter object or nil
48
- #
49
- # Thread.current[:union_station_hooks]
50
- # # => RequestReporter object or nil
51
- #
52
- # If this method was already called on this Rack request, then this method
53
- # does nothing and merely returns the previously created {RequestReporter}.
54
- #
55
- # See {RequestReporter} to learn what kind of information you can log to
56
- # Union Station about Rack requests.
57
- #
58
- # @return [RequestReporter, nil] A {RequestReporter} object, or nil or
59
- # because of certain error conditions. See the RequestReporter class
60
- # description for when this may be nil.
61
- def begin_rack_request(rack_env)
62
- reporter = rack_env['union_station_hooks']
63
- return reporter if reporter
64
-
65
- # PASSENGER_TXN_ID may be nil here even if Union Station support is
66
- # enabled. For example, if the user tried to access the application
67
- # process directly through its private HTTP socket.
68
- txn_id = rack_env['PASSENGER_TXN_ID']
69
- return nil if !txn_id
70
-
71
- # Workaround for Ruby < 2.1 support where there is no function for querying
72
- # the monotonic time.
73
- delta_monotonic_env = rack_env['PASSENGER_DELTA_MONOTONIC']
74
- set_delta_monotonic(delta_monotonic_env.to_i) if delta_monotonic_env
75
-
76
- reporter = RequestReporter.new(context, txn_id, app_group_name, key)
77
- return if reporter.null?
78
-
79
- rack_env['union_station_hooks'] = reporter
80
- Thread.current[:union_station_hooks] = reporter
81
- reporter.log_request_begin
82
- reporter.log_gc_stats_on_request_begin
83
- reporter
84
- end
85
-
86
- # @note You do not have to call this! Passenger automatically calls
87
- # this for you!
88
- #
89
- # Indicates that a Rack request, on which {begin_rack_request} was called,
90
- # has ended. You should call this method as late as possible during a
91
- # request, after all processing have ended. Preferably after the Rack
92
- # response body has closed.
93
- #
94
- # The {RequestReporter} object associated with this Rack request and with
95
- # the current, will be closed (by calling {RequestReporter#close}), which
96
- # finalizes the Union Station logs for this request.
97
- #
98
- # This method MUST be called in the same thread that called
99
- # {begin_rack_request}.
100
- #
101
- # It is undefined what will happen if you call this method a Rack request
102
- # on which {begin_rack_request} was not called, so don't do that.
103
- #
104
- # This method does nothing if it was already called on this Rack request.
105
- def end_rack_request(rack_env,
106
- uncaught_exception_raised_during_request = false)
107
- reporter = rack_env.delete('union_station_hooks')
108
- Thread.current[:union_station_hooks] = nil
109
- if reporter
110
- begin
111
- reporter.log_gc_stats_on_request_end
112
- reporter.log_request_end(uncaught_exception_raised_during_request)
113
- ensure
114
- reporter.close
115
- end
116
- end
117
- end
118
-
119
- # Logs an exception that did NOT occur during a request.
120
- #
121
- # This method should be used for logging exceptions outside the
122
- # request-response cycle, e.g. exceptions in threads. If you want to
123
- # log an exception that occurred during a request, use
124
- # {RequestReporter#log_exception} instead. That method will also log
125
- # any related request-specific information, while this method does not.
126
- #
127
- # @param [Exception] exception
128
- # @since 2.1.0
129
- def log_exception(exception)
130
- transaction = context.new_transaction(app_group_name, :exceptions, key)
131
- begin
132
- return do_nothing_on_null(:log_exception) if transaction.null?
133
-
134
- base64_message = exception.message
135
- base64_message = exception.to_s if base64_message.empty?
136
- base64_message = Utils.base64(base64_message)
137
- base64_backtrace = Utils.base64(exception.backtrace.join("\n"))
138
-
139
- transaction.message("Message: #{base64_message}")
140
- transaction.message("Class: #{exception.class.name}")
141
- transaction.message("Backtrace: #{base64_backtrace}")
142
- ensure
143
- transaction.close
144
- end
145
- end
146
-
147
- # Returns an opaque object (a {TimePoint}) that represents a collection
148
- # of metrics about the current time.
149
- #
150
- # This TimePoint samples monotonic time (with a fallback to wall clock
151
- # time) as well as CPU time, time spent in userspace and kernel space,
152
- # time spent context switching, etc. The exact information contained
153
- # in the object is operating system specific, hence the object is opaque.
154
- #
155
- # You should use it for the various API methods that require timing
156
- # information. Those methods also accept standard Ruby `Time` objects,
157
- # but we strongly recommended against doing this, because wall clock
158
- # time can jump forwards and backwards, which may create issues.
159
- #
160
- # See {RequestReporter#log_controller_action} for an example of
161
- # an API method which expects timing information.
162
- # `RequestReporter#log_controller_action` expects you to
163
- # provide timing information about a controller action. That timing
164
- # information is supposed to be obtained by calling
165
- # `UnionStationHooks.now`.
166
- #
167
- # @return [TimePoint]
168
- def now
169
- monotime_usec = Utils.monotime_usec_now
170
- pt = Utils.process_times
171
- TimePoint.new(monotime_usec, pt.utime, pt.stime)
172
- end
173
-
174
- # Returns a best-estimate delta (usec) between the wallclock and
175
- # the monotonic clock (updated every request), such that:
176
- # time_monotic_usec = time_wallclock_usec - delta
177
- def get_delta_monotonic
178
- @mono_mutex.synchronize { @delta_monotonic }
179
- end
180
-
181
- private
182
-
183
- # Although the de-facto state seems to be that reading/writing instance variables
184
- # is MT-safe, it's not guaranteed so better safe than sorry here.
185
- def set_delta_monotonic(val)
186
- @mono_mutex.synchronize { @delta_monotonic = val }
187
- end
188
-
189
- def create_context
190
- require_lib('context')
191
- @@context = Context.new(config[:ust_router_address],
192
- config[:ust_router_username] || 'logging',
193
- config[:ust_router_password],
194
- config[:node_name])
195
- end
196
-
197
- def install_postfork_hook
198
- if defined?(PhusionPassenger)
199
- PhusionPassenger.on_event(:starting_worker_process) do |forked|
200
- if forked
201
- UnionStationHooks.context.clear_connection
202
- end
203
- end
204
- end
205
- end
206
-
207
- def install_event_pre_hook
208
- preprocessor = @@config[:event_preprocessor]
209
- if preprocessor
210
- define_singleton_method(:call_event_pre_hook, &preprocessor)
211
- else
212
- def call_event_pre_hook(_event)
213
- # Do nothing
214
- end
215
- end
216
- end
217
-
218
- def initialize_other_union_station_hooks_gems
219
- @@initializers.each do |initializer|
220
- initializer.initialize!
221
- end
222
- end
223
-
224
- def finalize_install
225
- @@config.freeze
226
- @@initializers.freeze
227
- @@app_group_name = @@config[:app_group_name]
228
- @@key = @@config[:union_station_key]
229
- if @@config[:debug]
230
- UnionStationHooks::Log.debugging = true
231
- end
232
- require_simple_json
233
- @mono_mutex = Mutex.new
234
- @delta_monotonic = 0
235
- @@initialized = true
236
- end
237
- end
238
- end
@@ -1,67 +0,0 @@
1
- # Union Station - https://www.unionstationapp.com/
2
- # Copyright (c) 2010-2015 Phusion Holding B.V.
3
- #
4
- # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- require 'thread'
25
- UnionStationHooks.require_lib 'message_channel'
26
-
27
- module UnionStationHooks
28
- # Represents a connection to the UstRouter process.
29
- #
30
- # @private
31
- class Connection
32
- attr_reader :mutex
33
- attr_accessor :channel
34
-
35
- def initialize(io)
36
- @mutex = Mutex.new
37
- @refcount = 1
38
- @channel = MessageChannel.new(io) if io
39
- end
40
-
41
- def connected?
42
- !!@channel
43
- end
44
-
45
- def disconnect
46
- @channel.io.close if @channel
47
- @channel = nil
48
- end
49
-
50
- def ref
51
- @refcount += 1
52
- end
53
-
54
- def unref
55
- @refcount -= 1
56
- if @refcount == 0
57
- disconnect
58
- end
59
- end
60
-
61
- def synchronize
62
- @mutex.synchronize do
63
- yield
64
- end
65
- end
66
- end
67
- end
@@ -1,281 +0,0 @@
1
- # Union Station - https://www.unionstationapp.com/
2
- # Copyright (c) 2010-2015 Phusion Holding B.V.
3
- #
4
- # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- require 'thread'
25
- require 'socket'
26
- UnionStationHooks.require_lib 'connection'
27
- UnionStationHooks.require_lib 'transaction'
28
- UnionStationHooks.require_lib 'log'
29
- UnionStationHooks.require_lib 'lock'
30
- UnionStationHooks.require_lib 'utils'
31
-
32
- module UnionStationHooks
33
- # A Context object is the "heart" of all `union_station_hooks_*` gems. It
34
- # contains a connection to the UstRouter (through a Connection object)
35
- # and allows you to create Transaction objects.
36
- #
37
- # Context is a singleton. During initialization
38
- # (`UnionStationHooks.initialize!`), an instance is created and stored in
39
- # `UnionStationHooks.context`. All the public API methods make use of this
40
- # singleton context.
41
- #
42
- # See hacking/Architecture.md for an overview.
43
- #
44
- # @private
45
- class Context
46
- RETRY_SLEEP = 0.2
47
- NETWORK_ERRORS = [
48
- Errno::EPIPE, Errno::ECONNREFUSED, Errno::ECONNRESET,
49
- Errno::EHOSTUNREACH, Errno::ENETDOWN, Errno::ENETUNREACH,
50
- Errno::ETIMEDOUT
51
- ]
52
-
53
- include Utils
54
-
55
- attr_accessor :max_connect_tries
56
- attr_accessor :reconnect_timeout
57
-
58
- def initialize(ust_router_address, username, password, node_name)
59
- @server_address = ust_router_address
60
- @username = username
61
- @password = password
62
- if node_name && node_name.empty?
63
- @node_name = nil
64
- end
65
-
66
- # This mutex protects the following instance variables, but
67
- # not the contents of @connection.
68
- @mutex = Mutex.new
69
-
70
- @connection = Connection.new(nil)
71
- if @server_address && local_socket_address?(@server_address)
72
- @max_connect_tries = 10
73
- else
74
- @max_connect_tries = 1
75
- end
76
- @reconnect_timeout = 1
77
- @next_reconnect_time = Time.utc(1980, 1, 1)
78
- end
79
-
80
- def connection
81
- @mutex.synchronize do
82
- @connection
83
- end
84
- end
85
-
86
- def clear_connection
87
- @mutex.synchronize do
88
- @connection.synchronize do
89
- @connection.unref
90
- @connection = Connection.new(nil)
91
- end
92
- end
93
- end
94
-
95
- def close
96
- @mutex.synchronize do
97
- @connection.synchronize do
98
- @connection.unref
99
- @connection = nil
100
- end
101
- end
102
- end
103
-
104
- def new_transaction(group_name, category, key)
105
- if !@server_address
106
- return Transaction.new(nil, nil)
107
- elsif !group_name || group_name.empty?
108
- raise ArgumentError, 'Group name may not be empty'
109
- end
110
-
111
- Lock.new(@mutex).synchronize do |_lock|
112
- if Time.now < @next_reconnect_time
113
- return Transaction.new(nil, nil)
114
- end
115
-
116
- Lock.new(@connection.mutex).synchronize do |connection_lock|
117
- if !@connection.connected?
118
- begin
119
- connect
120
- connection_lock.reset(@connection.mutex)
121
- rescue SystemCallError, IOError
122
- @connection.disconnect
123
- UnionStationHooks::Log.warn(
124
- "Cannot connect to the UstRouter at #{@server_address}; " \
125
- "retrying in #{@reconnect_timeout} second(s).")
126
- @next_reconnect_time = Time.now + @reconnect_timeout
127
- return Transaction.new(nil, nil)
128
- rescue Exception => e
129
- @connection.disconnect
130
- raise e
131
- end
132
- end
133
-
134
- begin
135
- @connection.channel.write('openTransaction',
136
- '', group_name, '', category,
137
- Utils.encoded_timestamp,
138
- key,
139
- true,
140
- true)
141
- result = @connection.channel.read
142
- if result[0] != 'status'
143
- raise "Expected UstRouter to respond with 'status', " \
144
- "but got #{result.inspect} instead"
145
- elsif result[1] == 'error'
146
- if result[2]
147
- raise "Unable to close transaction: #{result[2]}"
148
- else
149
- raise 'Unable to close transaction (no server message given)'
150
- end
151
- elsif result[1] != 'ok'
152
- raise "Expected UstRouter to respond with 'ok' or 'error', " \
153
- "but got #{result.inspect} instead"
154
- elsif result.size < 3
155
- raise 'Expected UstRouter to respond with an autogenerated ' \
156
- 'transaction ID, but got none'
157
- end
158
-
159
- return Transaction.new(@connection, result[2])
160
- rescue SystemCallError, IOError
161
- @connection.disconnect
162
- UnionStationHooks::Log.warn(
163
- "The UstRouter at #{@server_address}" \
164
- ' closed the connection; will reconnect in ' \
165
- "#{@reconnect_timeout} second(s).")
166
- @next_reconnect_time = Time.now + @reconnect_timeout
167
- return Transaction.new(nil, nil)
168
- rescue Exception => e
169
- @connection.disconnect
170
- raise e
171
- end
172
- end
173
- end
174
- end
175
-
176
- def continue_transaction(txn_id, group_name, category, key)
177
- if !@server_address
178
- return Transaction.new(nil, nil)
179
- elsif !txn_id || txn_id.empty?
180
- raise ArgumentError, 'Transaction ID may not be empty'
181
- end
182
-
183
- Lock.new(@mutex).synchronize do |_lock|
184
- if Time.now < @next_reconnect_time
185
- return Transaction.new(nil, nil)
186
- end
187
-
188
- Lock.new(@connection.mutex).synchronize do |connection_lock|
189
- if !@connection.connected?
190
- begin
191
- connect
192
- connection_lock.reset(@connection.mutex)
193
- rescue SystemCallError, IOError
194
- @connection.disconnect
195
- UnionStationHooks::Log.warn(
196
- "Cannot connect to the UstRouter at #{@server_address}; " \
197
- "retrying in #{@reconnect_timeout} second(s).")
198
- @next_reconnect_time = Time.now + @reconnect_timeout
199
- return Transaction.new(nil, nil)
200
- rescue Exception => e
201
- @connection.disconnect
202
- raise e
203
- end
204
- end
205
-
206
- begin
207
- @connection.channel.write('openTransaction',
208
- txn_id, group_name, '', category,
209
- Utils.encoded_timestamp,
210
- key,
211
- true)
212
- return Transaction.new(@connection, txn_id)
213
- rescue SystemCallError, IOError
214
- @connection.disconnect
215
- UnionStationHooks::Log.warn(
216
- "The UstRouter at #{@server_address}" \
217
- ' closed the connection; will reconnect in ' \
218
- "#{@reconnect_timeout} second(s).")
219
- @next_reconnect_time = Time.now + @reconnect_timeout
220
- return Transaction.new(nil, nil)
221
- rescue Exception => e
222
- @connection.disconnect
223
- raise e
224
- end
225
- end
226
- end
227
- end
228
-
229
- private
230
-
231
- RANDOM_CHARS = %w(
232
- a b c d e f g h i j k l m n o p q r s t u v w x y z
233
- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
234
- 0 1 2 3 4 5 6 7 8 9
235
- )
236
-
237
- def connect
238
- socket = connect_to_server(@server_address)
239
- channel = MessageChannel.new(socket)
240
-
241
- handshake_version(channel)
242
- handshake_authentication(channel)
243
- handshake_initialization(channel)
244
-
245
- @connection.unref
246
- @connection = Connection.new(socket)
247
- rescue Exception => e
248
- socket.close if socket && !socket.closed?
249
- raise e
250
- end
251
-
252
- def handshake_version(channel)
253
- result = channel.read
254
- if result.nil?
255
- raise EOFError
256
- elsif result.size != 2 || result[0] != 'version'
257
- raise IOError, "The UstRouter didn't sent a valid version identifier"
258
- elsif result[1] != '1'
259
- raise IOError, "Unsupported UstRouter protocol version #{result[1]}"
260
- end
261
- end
262
-
263
- def handshake_authentication(channel)
264
- channel.write_scalar(@username)
265
- channel.write_scalar(@password)
266
- process_ust_router_reply(channel,
267
- 'UstRouter client authentication error',
268
- SecurityError)
269
- end
270
-
271
- def handshake_initialization(channel)
272
- if @node_name
273
- channel.write('init', @node_name)
274
- else
275
- channel.write('init')
276
- end
277
- process_ust_router_reply(channel,
278
- 'UstRouter client initialization error')
279
- end
280
- end
281
- end