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.
- checksums.yaml +4 -4
- data/CHANGELOG +13 -0
- data/CONTRIBUTORS +5 -1
- data/build/agent.rb +22 -2
- data/build/cxx_tests.rb +41 -5
- data/build/misc.rb +4 -1
- data/build/support/cxx_dependency_map.rb +1746 -908
- data/build/support/vendor/cxx_hinted_parser/CxxHintedParser.sublime-project +8 -0
- data/build/support/vendor/cxx_hinted_parser/Gemfile +5 -0
- data/build/support/vendor/cxx_hinted_parser/Gemfile.lock +30 -0
- data/{src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core → build/support/vendor/cxx_hinted_parser}/LICENSE.md +1 -1
- data/build/support/vendor/cxx_hinted_parser/README.md +95 -0
- data/build/support/vendor/cxx_hinted_parser/Rakefile +4 -0
- 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
- data/build/support/vendor/cxx_hinted_parser/lib/cxx_hinted_parser/parser.rb +239 -0
- data/dev/ci/README.md +15 -2
- data/dev/ci/lib/set-container-envvars.sh +6 -0
- data/dev/ci/lib/setup-container.sh +4 -1
- data/dev/ci/scripts/debug-console-wrapper.sh +3 -1
- data/dev/ci/setup-host +5 -0
- data/dev/ci/tests/binaries/Jenkinsfile +105 -0
- data/dev/ci/tests/binaries/build-linux +38 -0
- data/dev/ci/tests/binaries/build-macos +40 -0
- data/dev/ci/tests/binaries/prepare-macos +38 -0
- data/dev/ci/tests/binaries/test-linux +45 -0
- data/dev/ci/tests/binaries/test-macos +38 -0
- data/dev/ci/tests/debian/Jenkinsfile +2 -2
- data/dev/ci/tests/rpm/Jenkinsfile +1 -1
- data/dev/configkit-schemas/index.json +3 -24
- data/dev/vagrant/nginx_rakefile +0 -1
- data/package.json +15 -5
- data/resources/templates/error_renderer/.editorconfig +19 -0
- data/resources/templates/error_renderer/with_details/README.md +9 -0
- data/resources/templates/error_renderer/with_details/dist/bundle.js +33 -0
- data/resources/templates/error_renderer/with_details/dist/styles.css +17 -0
- data/resources/templates/error_renderer/with_details/src/DetailsView.jsx +52 -0
- data/resources/templates/error_renderer/with_details/src/GetHelpView.jsx +61 -0
- data/resources/templates/error_renderer/with_details/src/JourneyView.css +50 -0
- data/resources/templates/error_renderer/with_details/src/JourneyView.jsx +621 -0
- data/resources/templates/error_renderer/with_details/src/PageMain.css +114 -0
- data/resources/templates/error_renderer/with_details/src/PageMain.jsx +136 -0
- data/resources/templates/error_renderer/with_details/src/ProblemDescriptionView.jsx +14 -0
- data/resources/templates/error_renderer/with_details/src/ProcessDetailsView.jsx +56 -0
- data/resources/templates/error_renderer/with_details/src/SolutionDescriptionView.css +5 -0
- data/resources/templates/error_renderer/with_details/src/SolutionDescriptionView.jsx +15 -0
- data/resources/templates/error_renderer/with_details/src/SummaryView.jsx +35 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentView.css +34 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentView.jsx +168 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentsView.css +13 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentsView.jsx +116 -0
- data/resources/templates/error_renderer/with_details/src/Tab.jsx +12 -0
- data/resources/templates/error_renderer/with_details/src/Tabs.jsx +104 -0
- data/resources/templates/error_renderer/with_details/src/bootstrap/bootstrap.css +3446 -0
- data/resources/templates/error_renderer/with_details/src/bootstrap/bootstrap.js +293 -0
- data/resources/templates/error_renderer/with_details/src/bootstrap/config.json +401 -0
- data/resources/templates/error_renderer/with_details/src/index.html.template +22 -0
- data/resources/templates/error_renderer/with_details/src/index.jsx +23 -0
- data/resources/templates/error_renderer/with_details/webpack.config.js +47 -0
- data/resources/templates/error_renderer/without_details/dist/bundle.js +1 -0
- data/resources/templates/error_renderer/without_details/dist/styles.css +1 -0
- data/resources/templates/{undisclosed_error.html.template → error_renderer/without_details/src/index.html.template} +7 -11
- data/resources/templates/error_renderer/without_details/src/index.js +1 -0
- data/resources/templates/{error_layout.css → error_renderer/without_details/src/main.css} +5 -2
- data/resources/templates/error_renderer/without_details/webpack.config.js +42 -0
- data/src/agent/AgentMain.cpp +3 -3
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +13 -0
- data/src/agent/Core/ApplicationPool/Common.h +3 -4
- data/src/agent/Core/ApplicationPool/Context.h +27 -17
- data/src/agent/Core/ApplicationPool/Group.h +3 -1
- data/src/agent/Core/ApplicationPool/Group/InitializationAndShutdown.cpp +2 -12
- data/src/agent/Core/ApplicationPool/Group/InternalUtils.cpp +55 -10
- data/src/agent/Core/ApplicationPool/Group/LifetimeAndBasics.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/SpawningAndRestarting.cpp +13 -6
- data/src/agent/Core/ApplicationPool/Implementation.cpp +16 -100
- data/src/agent/Core/ApplicationPool/Options.h +8 -65
- data/src/agent/Core/ApplicationPool/Pool.h +4 -21
- data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +1 -60
- data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +10 -13
- data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +3 -8
- data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +2 -34
- data/src/agent/Core/ApplicationPool/Pool/StateInspection.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Process.cpp +17 -12
- data/src/agent/Core/ApplicationPool/Process.h +146 -93
- data/src/agent/Core/ApplicationPool/Session.h +2 -2
- data/src/agent/Core/ApplicationPool/Socket.h +28 -27
- data/src/agent/Core/Config.h +1 -3
- data/src/agent/Core/ConfigChange.cpp +2 -4
- data/src/agent/Core/Controller.h +2 -8
- data/src/agent/Core/Controller/BufferBody.cpp +0 -2
- data/src/agent/Core/Controller/CheckoutSession.cpp +12 -24
- data/src/agent/Core/Controller/Config.h +1 -9
- data/src/agent/Core/Controller/ForwardResponse.cpp +0 -34
- data/src/agent/Core/Controller/Hooks.cpp +0 -7
- data/src/agent/Core/Controller/InitRequest.cpp +0 -43
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +0 -4
- data/src/agent/Core/Controller/Request.h +1 -35
- data/src/agent/Core/Controller/SendRequest.cpp +0 -32
- data/src/agent/Core/CoreMain.cpp +19 -32
- data/src/agent/Core/SpawningKit/Config.h +329 -55
- data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h +369 -0
- data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h.cxxcodebuilder +307 -0
- data/src/agent/Core/SpawningKit/Context.h +211 -0
- data/src/agent/Core/SpawningKit/DirectSpawner.h +112 -122
- data/src/agent/Core/SpawningKit/DummySpawner.h +59 -20
- data/src/agent/Core/SpawningKit/ErrorRenderer.h +117 -0
- data/src/agent/Core/SpawningKit/Exceptions.h +1157 -0
- data/src/agent/Core/SpawningKit/Factory.h +24 -17
- data/src/agent/Core/SpawningKit/{BackgroundIOCapturer.h → Handshake/BackgroundIOCapturer.h} +48 -18
- data/src/agent/Core/SpawningKit/Handshake/Perform.h +1650 -0
- data/src/agent/Core/SpawningKit/Handshake/Prepare.h +582 -0
- data/src/agent/Core/SpawningKit/Handshake/Session.h +91 -0
- data/src/agent/Core/SpawningKit/Handshake/WorkDir.h +100 -0
- data/src/agent/Core/SpawningKit/Journey.h +561 -0
- data/src/agent/Core/SpawningKit/PipeWatcher.h +41 -18
- data/src/agent/Core/SpawningKit/README.md +534 -0
- data/src/agent/Core/SpawningKit/Result.h +182 -7
- data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h +69 -0
- data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h.cxxcodebuilder +110 -0
- data/src/agent/Core/SpawningKit/SmartSpawner.h +1027 -562
- data/src/agent/Core/SpawningKit/Spawner.h +70 -1134
- data/src/agent/Core/SpawningKit/UserSwitchingRules.h +3 -33
- data/src/agent/README.md +2 -3
- data/src/agent/Shared/ApiServerUtils.h +2 -3
- data/src/agent/SpawnEnvSetupper/SpawnEnvSetupperMain.cpp +932 -0
- data/src/agent/Watchdog/Config.h +1 -3
- data/src/agent/Watchdog/WatchdogMain.cpp +2 -1
- data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp +5 -0
- data/src/apache2_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.cpp +5 -0
- data/src/apache2_module/ConfigGeneral/ManifestGeneration.h +22 -13
- data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp +5 -0
- data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp +3 -0
- data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp +13 -0
- data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp +7 -0
- data/src/apache2_module/DirConfig/AutoGeneratedStruct.h +13 -0
- data/src/cxx_supportlib/Constants.h +3 -1
- data/src/cxx_supportlib/Exceptions.h +0 -121
- data/src/cxx_supportlib/LoggingKit/Implementation.cpp +7 -6
- data/src/cxx_supportlib/LoggingKit/Logging.h +3 -1
- data/src/cxx_supportlib/Utils.cpp +42 -0
- data/src/cxx_supportlib/Utils.h +7 -0
- data/src/cxx_supportlib/Utils/IOUtils.cpp +58 -0
- data/src/cxx_supportlib/Utils/IOUtils.h +13 -0
- data/src/cxx_supportlib/Utils/JsonUtils.h +130 -23
- data/src/cxx_supportlib/Utils/ScopeGuard.h +9 -4
- data/src/cxx_supportlib/Utils/StrIntUtils.cpp +7 -0
- data/src/cxx_supportlib/Utils/StrIntUtils.h +1 -0
- data/src/cxx_supportlib/Utils/SystemTime.h +1 -1
- data/src/cxx_supportlib/Utils/Timer.h +1 -1
- data/src/cxx_supportlib/WebSocketCommandReverseServer.h +6 -4
- data/src/cxx_supportlib/vendor-copy/adhoc_lve.h +1 -0
- data/src/helper-scripts/node-loader.js +54 -59
- data/src/helper-scripts/rack-loader.rb +63 -60
- data/src/helper-scripts/rack-preloader.rb +125 -72
- data/src/helper-scripts/wsgi-loader.py +100 -43
- data/src/nginx_module/ConfigGeneral/AutoGeneratedDefinitions.c +120 -112
- data/src/nginx_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.c +15 -8
- data/src/nginx_module/ConfigGeneral/AutoGeneratedSetterFuncs.c +142 -142
- data/src/nginx_module/ConfigGeneral/ManifestGeneration.c +26 -15
- data/src/nginx_module/ConfigGeneral/ManifestGeneration.h +3 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedCreateFunction.c +76 -70
- data/src/nginx_module/LocationConfig/AutoGeneratedHeaderSerialization.c +114 -99
- data/src/nginx_module/LocationConfig/AutoGeneratedManifestGeneration.c +170 -156
- data/src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c +38 -35
- data/src/nginx_module/LocationConfig/AutoGeneratedStruct.h +5 -1
- data/src/ruby_supportlib/phusion_passenger.rb +5 -5
- data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +14 -1
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/common_library.rb +0 -3
- data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +0 -1
- data/src/ruby_supportlib/phusion_passenger/constants.rb +2 -0
- data/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +646 -238
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +117 -95
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +0 -1
- data/src/ruby_supportlib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +5 -1
- data/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb +92 -69
- data/src/ruby_supportlib/phusion_passenger/public_api.rb +0 -17
- data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +0 -3
- data/src/ruby_supportlib/phusion_passenger/request_handler.rb +4 -5
- data/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb +0 -22
- metadata +64 -67
- data/resources/templates/error_layout.html.template +0 -86
- data/resources/templates/general_error.html.template +0 -1
- data/resources/templates/general_error_with_html.html.template +0 -1
- data/src/agent/Core/ApplicationPool/ErrorRenderer.h +0 -131
- data/src/agent/Core/SpawningKit/Options.h +0 -41
- data/src/agent/Core/UnionStation/Connection.h +0 -173
- data/src/agent/Core/UnionStation/Context.h +0 -536
- data/src/agent/Core/UnionStation/StopwatchLog.h +0 -147
- data/src/agent/Core/UnionStation/Transaction.h +0 -249
- data/src/agent/SpawnPreparer/SpawnPreparerMain.cpp +0 -208
- data/src/cxx_supportlib/UnionStationFilterSupport.cpp +0 -67
- data/src/cxx_supportlib/UnionStationFilterSupport.h +0 -1622
- data/src/nodejs_supportlib/phusion_passenger/log_express.js +0 -106
- data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +0 -202
- data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +0 -227
- data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +0 -448
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/CONFIG.md +0 -37
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Gemfile +0 -17
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Gemfile.lock +0 -59
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README-API.md +0 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +0 -117
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +0 -115
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +0 -423
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +0 -238
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/connection.rb +0 -67
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +0 -281
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/lock.rb +0 -62
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/log.rb +0 -66
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/message_channel.rb +0 -157
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +0 -150
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +0 -199
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/controllers.rb +0 -187
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/misc.rb +0 -303
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/view_rendering.rb +0 -91
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +0 -396
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/spec_helper.rb +0 -279
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/time_point.rb +0 -39
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +0 -173
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +0 -177
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version.rb +0 -32
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +0 -44
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +0 -16
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +0 -20
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +0 -18
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/union_station_hooks_core.gemspec +0 -23
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +0 -14
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +0 -45
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/LICENSE.md +0 -19
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +0 -104
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Rakefile +0 -160
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +0 -200
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/action_controller_extension.rb +0 -45
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/action_view_subscriber.rb +0 -55
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_record_subscriber.rb +0 -41
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_benchmarkable_extension.rb +0 -47
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +0 -79
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/exception_logger.rb +0 -57
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version.rb +0 -32
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +0 -44
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +0 -34
@@ -1 +0,0 @@
|
|
1
|
-
<pre>{{MESSAGE}}</pre>
|
@@ -1 +0,0 @@
|
|
1
|
-
{{MESSAGE|raw}}
|
@@ -1,131 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
-
* Copyright (c) 2014-2017 Phusion Holding B.V.
|
4
|
-
*
|
5
|
-
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
|
-
* trademarks of Phusion Holding B.V.
|
7
|
-
*
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
13
|
-
* furnished to do so, subject to the following conditions:
|
14
|
-
*
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
16
|
-
* all copies or substantial portions of the Software.
|
17
|
-
*
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
* THE SOFTWARE.
|
25
|
-
*/
|
26
|
-
#ifndef _PASSENGER_APPLICATION_POOL2_ERROR_RENDERER_H_
|
27
|
-
#define _PASSENGER_APPLICATION_POOL2_ERROR_RENDERER_H_
|
28
|
-
|
29
|
-
#include <string>
|
30
|
-
#include <map>
|
31
|
-
#include <cctype>
|
32
|
-
|
33
|
-
#include <Constants.h>
|
34
|
-
#include <ResourceLocator.h>
|
35
|
-
#include <StaticString.h>
|
36
|
-
#include <Exceptions.h>
|
37
|
-
#include <Utils/StringMap.h>
|
38
|
-
#include <Utils/Template.h>
|
39
|
-
#include <Utils/IOUtils.h>
|
40
|
-
#include <Core/ApplicationPool/Options.h>
|
41
|
-
|
42
|
-
namespace Passenger {
|
43
|
-
namespace ApplicationPool2 {
|
44
|
-
|
45
|
-
using namespace std;
|
46
|
-
using namespace boost;
|
47
|
-
using namespace oxt;
|
48
|
-
|
49
|
-
|
50
|
-
class ErrorRenderer {
|
51
|
-
private:
|
52
|
-
string templatesDir, cssFile, errorLayoutFile;
|
53
|
-
|
54
|
-
public:
|
55
|
-
ErrorRenderer(const ResourceLocator &resourceLocator) {
|
56
|
-
templatesDir = resourceLocator.getResourcesDir() + "/templates";
|
57
|
-
cssFile = templatesDir + "/error_layout.css";
|
58
|
-
errorLayoutFile = templatesDir + "/error_layout.html.template";
|
59
|
-
}
|
60
|
-
|
61
|
-
string renderWithDetails(const StaticString &message,
|
62
|
-
const Options &options,
|
63
|
-
const SpawnException *e = NULL) const
|
64
|
-
{
|
65
|
-
string generalErrorFile =
|
66
|
-
(e != NULL && e->isHTML())
|
67
|
-
? templatesDir + "/general_error_with_html.html.template"
|
68
|
-
: templatesDir + "/general_error.html.template";
|
69
|
-
string css = readAll(cssFile);
|
70
|
-
StringMap<StaticString> params;
|
71
|
-
|
72
|
-
params.set("CSS", css);
|
73
|
-
params.set("APP_ROOT", options.appRoot);
|
74
|
-
params.set("RUBY", options.ruby);
|
75
|
-
params.set("ENVIRONMENT", options.environment);
|
76
|
-
params.set("MESSAGE", message);
|
77
|
-
params.set("IS_RUBY_APP",
|
78
|
-
(options.appType == "rack")
|
79
|
-
? "true" : "false");
|
80
|
-
if (e != NULL) {
|
81
|
-
params.set("TITLE", "Web application could not be started");
|
82
|
-
// Store all SpawnException annotations into 'params',
|
83
|
-
// but convert its name to uppercase.
|
84
|
-
const map<string, string> &annotations = e->getAnnotations();
|
85
|
-
map<string, string>::const_iterator it, end = annotations.end();
|
86
|
-
for (it = annotations.begin(); it != end; it++) {
|
87
|
-
string name = it->first;
|
88
|
-
for (string::size_type i = 0; i < name.size(); i++) {
|
89
|
-
name[i] = toupper(name[i]);
|
90
|
-
}
|
91
|
-
params.set(name, it->second);
|
92
|
-
}
|
93
|
-
} else {
|
94
|
-
params.set("TITLE", "Internal server error");
|
95
|
-
}
|
96
|
-
|
97
|
-
string content = Template::apply(readAll(generalErrorFile), params);
|
98
|
-
params.set("CONTENT", content);
|
99
|
-
|
100
|
-
return Template::apply(readAll(errorLayoutFile), params);
|
101
|
-
}
|
102
|
-
|
103
|
-
string renderWithoutDetails(const SpawnException *e = NULL) const {
|
104
|
-
string templateFile = templatesDir + "/undisclosed_error.html.template";
|
105
|
-
string css = readAll(cssFile);
|
106
|
-
StringMap<StaticString> params;
|
107
|
-
|
108
|
-
params.set("PROGRAM_NAME", PROGRAM_NAME);
|
109
|
-
params.set("CSS", css);
|
110
|
-
params.set("TITLE", "Web application could not be started");
|
111
|
-
|
112
|
-
if (e != NULL) {
|
113
|
-
const map<string, string> &annotations = e->getAnnotations();
|
114
|
-
map<string, string>::const_iterator it = annotations.find("error_id");
|
115
|
-
if (it != annotations.end()) {
|
116
|
-
params.set("ERROR_ID", it->second);
|
117
|
-
} else {
|
118
|
-
params.set("ERROR_ID", "not available");
|
119
|
-
}
|
120
|
-
} else {
|
121
|
-
params.set("ERROR_ID", "not available");
|
122
|
-
}
|
123
|
-
return Template::apply(readAll(templateFile), params);
|
124
|
-
}
|
125
|
-
};
|
126
|
-
|
127
|
-
|
128
|
-
} // namespace ApplicationPool2
|
129
|
-
} // namespace Passenger
|
130
|
-
|
131
|
-
#endif /* _PASSENGER_APPLICATION_POOL2_ERROR_RENDERER_H_ */
|
@@ -1,41 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
-
* Copyright (c) 2015-2017 Phusion Holding B.V.
|
4
|
-
*
|
5
|
-
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
|
-
* trademarks of Phusion Holding B.V.
|
7
|
-
*
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
13
|
-
* furnished to do so, subject to the following conditions:
|
14
|
-
*
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
16
|
-
* all copies or substantial portions of the Software.
|
17
|
-
*
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
* THE SOFTWARE.
|
25
|
-
*/
|
26
|
-
#ifndef _PASSENGER_SPAWNING_KIT_OPTIONS_H_
|
27
|
-
#define _PASSENGER_SPAWNING_KIT_OPTIONS_H_
|
28
|
-
|
29
|
-
#include <Core/ApplicationPool/Options.h>
|
30
|
-
|
31
|
-
namespace Passenger {
|
32
|
-
namespace SpawningKit {
|
33
|
-
|
34
|
-
|
35
|
-
typedef ApplicationPool2::Options Options;
|
36
|
-
|
37
|
-
|
38
|
-
} // namespace SpawningKit
|
39
|
-
} // namespace Passenger
|
40
|
-
|
41
|
-
#endif /* _PASSENGER_SPAWNING_KIT_OPTIONS_H_ */
|
@@ -1,173 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
-
* Copyright (c) 2010-2017 Phusion Holding B.V.
|
4
|
-
*
|
5
|
-
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
|
-
* trademarks of Phusion Holding B.V.
|
7
|
-
*
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
13
|
-
* furnished to do so, subject to the following conditions:
|
14
|
-
*
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
16
|
-
* all copies or substantial portions of the Software.
|
17
|
-
*
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
* THE SOFTWARE.
|
25
|
-
*/
|
26
|
-
#ifndef _PASSENGER_UNION_STATION_CONNECTION_H_
|
27
|
-
#define _PASSENGER_UNION_STATION_CONNECTION_H_
|
28
|
-
|
29
|
-
#include <boost/thread.hpp>
|
30
|
-
#include <boost/shared_ptr.hpp>
|
31
|
-
#include <boost/noncopyable.hpp>
|
32
|
-
#include <oxt/system_calls.hpp>
|
33
|
-
#include <oxt/backtrace.hpp>
|
34
|
-
|
35
|
-
#include <string>
|
36
|
-
#include <vector>
|
37
|
-
|
38
|
-
#include <errno.h>
|
39
|
-
|
40
|
-
#include <LoggingKit/LoggingKit.h>
|
41
|
-
#include <Exceptions.h>
|
42
|
-
#include <Utils/IOUtils.h>
|
43
|
-
#include <Utils/MessageIO.h>
|
44
|
-
|
45
|
-
namespace Passenger {
|
46
|
-
namespace UnionStation {
|
47
|
-
|
48
|
-
using namespace std;
|
49
|
-
using namespace boost;
|
50
|
-
|
51
|
-
|
52
|
-
struct Connection;
|
53
|
-
typedef boost::shared_ptr<Connection> ConnectionPtr;
|
54
|
-
|
55
|
-
inline void _disconnectConnection(Connection *connection);
|
56
|
-
|
57
|
-
|
58
|
-
/**
|
59
|
-
* A scope guard which closes the given Connection on destruction unless cleared.
|
60
|
-
* Note that this class does not hold a shared_ptr to the Connection object,
|
61
|
-
* so make sure that the Connection outlives the guard object.
|
62
|
-
*/
|
63
|
-
class ConnectionGuard: public boost::noncopyable {
|
64
|
-
private:
|
65
|
-
Connection * const connection;
|
66
|
-
bool cleared;
|
67
|
-
|
68
|
-
public:
|
69
|
-
ConnectionGuard(Connection *_connection)
|
70
|
-
: connection(_connection),
|
71
|
-
cleared(false)
|
72
|
-
{ }
|
73
|
-
|
74
|
-
~ConnectionGuard() {
|
75
|
-
if (!cleared) {
|
76
|
-
_disconnectConnection(connection);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
void clear() {
|
81
|
-
cleared = true;
|
82
|
-
}
|
83
|
-
};
|
84
|
-
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Represents a connection to the UstRouter.
|
88
|
-
* All access to the file descriptor must be synchronized through the syncher.
|
89
|
-
* You can use the ConnectionLock to do that.
|
90
|
-
*/
|
91
|
-
struct Connection: public boost::noncopyable {
|
92
|
-
mutable boost::mutex syncher;
|
93
|
-
int fd;
|
94
|
-
|
95
|
-
Connection(int _fd)
|
96
|
-
: fd(_fd)
|
97
|
-
{ }
|
98
|
-
|
99
|
-
~Connection() {
|
100
|
-
disconnect();
|
101
|
-
}
|
102
|
-
|
103
|
-
bool connected() const {
|
104
|
-
return fd != -1;
|
105
|
-
}
|
106
|
-
|
107
|
-
void disconnect() {
|
108
|
-
if (fd != -1) {
|
109
|
-
boost::this_thread::disable_interruption di;
|
110
|
-
boost::this_thread::disable_syscall_interruption dsi;
|
111
|
-
safelyClose(fd);
|
112
|
-
P_LOG_FILE_DESCRIPTOR_CLOSE(fd);
|
113
|
-
fd = -1;
|
114
|
-
}
|
115
|
-
}
|
116
|
-
};
|
117
|
-
|
118
|
-
typedef boost::shared_ptr<Connection> ConnectionPtr;
|
119
|
-
|
120
|
-
|
121
|
-
/**
|
122
|
-
* A special lock type for Connection that also keeps a smart
|
123
|
-
* pointer to the data structure so that the mutex is not destroyed
|
124
|
-
* prematurely.
|
125
|
-
*/
|
126
|
-
struct ConnectionLock: public boost::noncopyable {
|
127
|
-
ConnectionPtr connection;
|
128
|
-
bool locked;
|
129
|
-
|
130
|
-
ConnectionLock(const ConnectionPtr &c)
|
131
|
-
: connection(c)
|
132
|
-
{
|
133
|
-
c->syncher.lock();
|
134
|
-
locked = true;
|
135
|
-
}
|
136
|
-
|
137
|
-
~ConnectionLock() {
|
138
|
-
if (locked) {
|
139
|
-
connection->syncher.unlock();
|
140
|
-
}
|
141
|
-
}
|
142
|
-
|
143
|
-
void reset(const ConnectionPtr &c, bool lockNow = true) {
|
144
|
-
if (locked) {
|
145
|
-
connection->syncher.unlock();
|
146
|
-
}
|
147
|
-
connection = c;
|
148
|
-
if (lockNow) {
|
149
|
-
connection->syncher.lock();
|
150
|
-
locked = true;
|
151
|
-
} else {
|
152
|
-
locked = false;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
void lock() {
|
157
|
-
assert(!locked);
|
158
|
-
connection->syncher.lock();
|
159
|
-
locked = true;
|
160
|
-
}
|
161
|
-
};
|
162
|
-
|
163
|
-
|
164
|
-
inline void
|
165
|
-
_disconnectConnection(Connection *connection) {
|
166
|
-
connection->disconnect();
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
} // namespace UnionStation
|
171
|
-
} // namespace Passenger
|
172
|
-
|
173
|
-
#endif /* _PASSENGER_UNION_STATION_CONNECTION_H_ */
|
@@ -1,536 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
-
* Copyright (c) 2010-2017 Phusion Holding B.V.
|
4
|
-
*
|
5
|
-
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
|
-
* trademarks of Phusion Holding B.V.
|
7
|
-
*
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
13
|
-
* furnished to do so, subject to the following conditions:
|
14
|
-
*
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
16
|
-
* all copies or substantial portions of the Software.
|
17
|
-
*
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
* THE SOFTWARE.
|
25
|
-
*/
|
26
|
-
#ifndef _PASSENGER_UNION_STATION_CONTEXT_H_
|
27
|
-
#define _PASSENGER_UNION_STATION_CONTEXT_H_
|
28
|
-
|
29
|
-
#include <boost/shared_ptr.hpp>
|
30
|
-
#include <boost/enable_shared_from_this.hpp>
|
31
|
-
#include <boost/thread.hpp>
|
32
|
-
#include <oxt/backtrace.hpp>
|
33
|
-
|
34
|
-
#include <errno.h>
|
35
|
-
|
36
|
-
#include <string>
|
37
|
-
#include <vector>
|
38
|
-
#include <stdexcept>
|
39
|
-
|
40
|
-
#include <LoggingKit/LoggingKit.h>
|
41
|
-
#include <Exceptions.h>
|
42
|
-
#include <StaticString.h>
|
43
|
-
#include <Utils.h>
|
44
|
-
#include <Utils/MessageIO.h>
|
45
|
-
#include <Utils/SystemTime.h>
|
46
|
-
#include <Core/UnionStation/Connection.h>
|
47
|
-
#include <Core/UnionStation/Transaction.h>
|
48
|
-
|
49
|
-
namespace Passenger {
|
50
|
-
namespace UnionStation {
|
51
|
-
|
52
|
-
using namespace std;
|
53
|
-
using namespace boost;
|
54
|
-
|
55
|
-
|
56
|
-
class Context: public boost::enable_shared_from_this<Context> {
|
57
|
-
private:
|
58
|
-
static const unsigned int CONNECTION_POOL_MAX_SIZE = 10;
|
59
|
-
|
60
|
-
/**** Server information ****/
|
61
|
-
const string serverAddress;
|
62
|
-
const string username;
|
63
|
-
const string password;
|
64
|
-
const string nodeName;
|
65
|
-
|
66
|
-
/**** Working objects ****/
|
67
|
-
TransactionPtr nullTransaction;
|
68
|
-
|
69
|
-
/********************** Connection handling fields **********************
|
70
|
-
* These fields are synchronized through the mutex. The contents
|
71
|
-
* of the conntection objects are not synchronized through this mutex,
|
72
|
-
* but through the Connection object's own mutex.
|
73
|
-
************************************************************************/
|
74
|
-
mutable boost::mutex syncher;
|
75
|
-
vector<ConnectionPtr> connectionPool;
|
76
|
-
/** How long to wait before reconnecting. */
|
77
|
-
unsigned long long reconnectTimeout;
|
78
|
-
/** Earliest time at which we should attempt a reconnect. Earlier attempts
|
79
|
-
* will fail. Calculated from reconnectTimeout.
|
80
|
-
*/
|
81
|
-
unsigned long long nextReconnectTime;
|
82
|
-
|
83
|
-
static bool isNetworkError(int code) {
|
84
|
-
return code == EPIPE || code == ECONNREFUSED || code == ECONNRESET
|
85
|
-
|| code == EHOSTUNREACH || code == ENETDOWN || code == ENETUNREACH
|
86
|
-
|| code == ETIMEDOUT;
|
87
|
-
}
|
88
|
-
|
89
|
-
template<typename T>
|
90
|
-
static bool instanceof(const std::exception &e) {
|
91
|
-
return dynamic_cast<const T *>(&e) != NULL;
|
92
|
-
}
|
93
|
-
|
94
|
-
void initialize() {
|
95
|
-
nullTransaction = boost::make_shared<Transaction>();
|
96
|
-
reconnectTimeout = 1000000;
|
97
|
-
nextReconnectTime = 0;
|
98
|
-
}
|
99
|
-
|
100
|
-
ConnectionPtr createNewConnection() {
|
101
|
-
TRACE_POINT();
|
102
|
-
int fd;
|
103
|
-
vector<string> args;
|
104
|
-
unsigned long long timeout = 15000000;
|
105
|
-
|
106
|
-
// Create socket.
|
107
|
-
fd = connectToServer(serverAddress, __FILE__, __LINE__);
|
108
|
-
FdGuard guard(fd, NULL, 0, true);
|
109
|
-
|
110
|
-
P_LOG_FILE_DESCRIPTOR_PURPOSE(fd, "Connection to " SHORT_PROGRAM_NAME " UstRouter");
|
111
|
-
|
112
|
-
// Handshake: process protocol version number.
|
113
|
-
if (!readArrayMessage(fd, args, &timeout)) {
|
114
|
-
throw IOException("The UstRouter closed the connection before sending a version identifier");
|
115
|
-
}
|
116
|
-
if (args.size() != 2 || args[0] != "version") {
|
117
|
-
throw IOException("The UstRouter didn't sent a valid version identifier");
|
118
|
-
}
|
119
|
-
if (args[1] != "1") {
|
120
|
-
string message = "Unsupported UstRouter protocol version " +
|
121
|
-
args[1] + ".";
|
122
|
-
throw IOException(message);
|
123
|
-
}
|
124
|
-
|
125
|
-
// Handshake: authenticate.
|
126
|
-
UPDATE_TRACE_POINT();
|
127
|
-
writeScalarMessage(fd, username, &timeout);
|
128
|
-
writeScalarMessage(fd, password, &timeout);
|
129
|
-
|
130
|
-
UPDATE_TRACE_POINT();
|
131
|
-
if (!readArrayMessage(fd, args, &timeout)) {
|
132
|
-
throw IOException("The UstRouter did not send an authentication response");
|
133
|
-
} else if (args.size() < 2 || args[0] != "status") {
|
134
|
-
throw IOException("The authentication response that the UstRouter sent is not valid");
|
135
|
-
} else if (args[1] == "ok") {
|
136
|
-
// Do nothing
|
137
|
-
} else if (args[1] == "error") {
|
138
|
-
if (args.size() >= 3) {
|
139
|
-
throw SecurityException("The UstRouter denied authentication: " + args[2]);
|
140
|
-
} else {
|
141
|
-
throw SecurityException("The UstRouter denied authentication (no server message given)");
|
142
|
-
}
|
143
|
-
} else {
|
144
|
-
throw IOException("The authentication response that the UstRouter sent is not valid");
|
145
|
-
}
|
146
|
-
|
147
|
-
// Initialize session.
|
148
|
-
UPDATE_TRACE_POINT();
|
149
|
-
if (nodeName.empty()) {
|
150
|
-
writeArrayMessage(fd, &timeout, "init", NULL);
|
151
|
-
} else {
|
152
|
-
writeArrayMessage(fd, &timeout, "init", nodeName.c_str(), NULL);
|
153
|
-
}
|
154
|
-
if (!readArrayMessage(fd, args, &timeout)) {
|
155
|
-
throw SystemException("Cannot connect to the UstRouter", ECONNREFUSED);
|
156
|
-
} else if (args.size() < 2 || args[0] != "status") {
|
157
|
-
throw IOException("The UstRouter returned an invalid reply for the 'init' command");
|
158
|
-
} else if (args[1] == "ok") {
|
159
|
-
// Do nothing
|
160
|
-
} else if (args[1] == "error") {
|
161
|
-
if (args.size() >= 3) {
|
162
|
-
throw IOException("The UstRouter denied client initialization: " + args[2]);
|
163
|
-
} else {
|
164
|
-
throw IOException("The UstRouter denied client initialization (no server message given)");
|
165
|
-
}
|
166
|
-
} else {
|
167
|
-
throw IOException("The UstRouter returned an invalid reply for the 'init' command");
|
168
|
-
}
|
169
|
-
|
170
|
-
ConnectionPtr connection = boost::make_shared<Connection>(fd);
|
171
|
-
guard.clear();
|
172
|
-
return connection;
|
173
|
-
}
|
174
|
-
|
175
|
-
public:
|
176
|
-
Context() {
|
177
|
-
initialize();
|
178
|
-
}
|
179
|
-
|
180
|
-
Context(const string &_serverAddress, const string &_username,
|
181
|
-
const string &_password, const string &_nodeName = string())
|
182
|
-
: serverAddress(_serverAddress),
|
183
|
-
username(_username),
|
184
|
-
password(_password),
|
185
|
-
nodeName(_nodeName)
|
186
|
-
{
|
187
|
-
initialize();
|
188
|
-
}
|
189
|
-
|
190
|
-
|
191
|
-
/***** Connection pool methods *****/
|
192
|
-
|
193
|
-
ConnectionPtr checkoutConnection() {
|
194
|
-
TRACE_POINT();
|
195
|
-
boost::unique_lock<boost::mutex> l(syncher);
|
196
|
-
if (!connectionPool.empty()) {
|
197
|
-
P_TRACE(3, "Checked out existing connection");
|
198
|
-
ConnectionPtr connection = connectionPool.back();
|
199
|
-
connectionPool.pop_back();
|
200
|
-
return connection;
|
201
|
-
|
202
|
-
} else {
|
203
|
-
if (SystemTime::getUsec() < nextReconnectTime) {
|
204
|
-
P_TRACE(3, "Not yet time to reconnect; returning NULL connection");
|
205
|
-
return ConnectionPtr();
|
206
|
-
}
|
207
|
-
|
208
|
-
l.unlock();
|
209
|
-
P_TRACE(3, "Creating new connection with UstRouter");
|
210
|
-
ConnectionPtr connection;
|
211
|
-
try {
|
212
|
-
connection = createNewConnection();
|
213
|
-
} catch (const TimeoutException &) {
|
214
|
-
l.lock();
|
215
|
-
P_WARN("Timeout trying to connect to the UstRouter at " << serverAddress << "; " <<
|
216
|
-
"will reconnect in " << reconnectTimeout / 1000000 << " second(s).");
|
217
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
218
|
-
return ConnectionPtr();
|
219
|
-
} catch (const tracable_exception &e) {
|
220
|
-
l.lock();
|
221
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
222
|
-
if (instanceof<IOException>(e) || instanceof<SystemException>(e)) {
|
223
|
-
P_WARN("Cannot connect to the UstRouter at " << serverAddress <<
|
224
|
-
" (" << e.what() << "); will reconnect in " <<
|
225
|
-
reconnectTimeout / 1000000 << " second(s).");
|
226
|
-
return ConnectionPtr();
|
227
|
-
} else {
|
228
|
-
throw;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
|
232
|
-
return connection;
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
void checkinConnection(const ConnectionPtr &connection) {
|
237
|
-
boost::unique_lock<boost::mutex> l(syncher);
|
238
|
-
if (connectionPool.size() < CONNECTION_POOL_MAX_SIZE) {
|
239
|
-
connectionPool.push_back(connection);
|
240
|
-
} else {
|
241
|
-
l.unlock();
|
242
|
-
connection->disconnect();
|
243
|
-
}
|
244
|
-
}
|
245
|
-
|
246
|
-
|
247
|
-
/***** Transaction methods *****/
|
248
|
-
|
249
|
-
TransactionPtr createNullTransaction() const {
|
250
|
-
return nullTransaction;
|
251
|
-
}
|
252
|
-
|
253
|
-
void handleTimeout() {
|
254
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
255
|
-
P_WARN("Timeout trying to communicate with the UstRouter at " <<
|
256
|
-
serverAddress << "; " << "will reconnect in " <<
|
257
|
-
reconnectTimeout / 1000000 << " second(s).");
|
258
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
259
|
-
}
|
260
|
-
|
261
|
-
void handleNetworkErrorOrThrow(const ConnectionPtr &connection,
|
262
|
-
ConnectionGuard &guard, const SystemException &e)
|
263
|
-
{
|
264
|
-
if (e.code() == ENOENT || isNetworkError(e.code())) {
|
265
|
-
guard.clear();
|
266
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
267
|
-
P_WARN("The UstRouter at " << serverAddress <<
|
268
|
-
" closed the connection (no error message given);" <<
|
269
|
-
" will reconnect in " << reconnectTimeout / 1000000 <<
|
270
|
-
" second(s).");
|
271
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
272
|
-
} else {
|
273
|
-
throw e;
|
274
|
-
}
|
275
|
-
}
|
276
|
-
|
277
|
-
bool sendRequest(const ConnectionPtr &connection, StaticString argsSend[],
|
278
|
-
unsigned int nrArgsSend)
|
279
|
-
{
|
280
|
-
ConnectionLock cl(connection);
|
281
|
-
ConnectionGuard guard(connection.get());
|
282
|
-
|
283
|
-
try {
|
284
|
-
unsigned long long timeout = 15000000;
|
285
|
-
|
286
|
-
writeArrayMessage(connection->fd, argsSend, nrArgsSend, &timeout);
|
287
|
-
|
288
|
-
guard.clear();
|
289
|
-
return true;
|
290
|
-
} catch (const TimeoutException &) {
|
291
|
-
handleTimeout();
|
292
|
-
return false;
|
293
|
-
} catch (const SystemException &e) {
|
294
|
-
handleNetworkErrorOrThrow(connection, guard, e);
|
295
|
-
return false;
|
296
|
-
}
|
297
|
-
}
|
298
|
-
|
299
|
-
bool sendRequestGetResponse(const ConnectionPtr &connection,
|
300
|
-
StaticString argsSend[], unsigned int nrArgsSend,
|
301
|
-
vector<string> &argsReply, unsigned int expectedExtraReplyArgs = 0)
|
302
|
-
{
|
303
|
-
ConnectionLock cl(connection);
|
304
|
-
ConnectionGuard guard(connection.get());
|
305
|
-
|
306
|
-
try {
|
307
|
-
unsigned long long timeout = 15000000;
|
308
|
-
|
309
|
-
writeArrayMessage(connection->fd, argsSend, nrArgsSend, &timeout);
|
310
|
-
|
311
|
-
if (!readArrayMessage(connection->fd, argsReply, &timeout)) {
|
312
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
313
|
-
P_WARN("The UstRouter at " << serverAddress <<
|
314
|
-
" closed the connection (no error message given);" <<
|
315
|
-
" will reconnect in " << reconnectTimeout / 1000000 <<
|
316
|
-
" second(s).");
|
317
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
318
|
-
return false;
|
319
|
-
}
|
320
|
-
|
321
|
-
if (argsReply.size() < 2 || argsReply[0] != "status") {
|
322
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
323
|
-
P_WARN("The UstRouter sent an invalid reply message;" <<
|
324
|
-
" will reconnect in " << reconnectTimeout / 1000000 <<
|
325
|
-
" second(s).");
|
326
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
327
|
-
return false;
|
328
|
-
}
|
329
|
-
|
330
|
-
if (argsReply[1] == "error") {
|
331
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
332
|
-
if (argsReply.size() >= 3) {
|
333
|
-
P_WARN("The UstRouter closed the connection "
|
334
|
-
"(error message: " << argsReply[2] <<
|
335
|
-
"); will reconnect in " <<
|
336
|
-
reconnectTimeout / 1000000 <<
|
337
|
-
" second(s).");
|
338
|
-
} else {
|
339
|
-
P_WARN("The UstRouter closed the connection "
|
340
|
-
"(no server message given); " <<
|
341
|
-
"will reconnect in " <<
|
342
|
-
reconnectTimeout / 1000000 <<
|
343
|
-
" second(s).");
|
344
|
-
}
|
345
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
346
|
-
return false;
|
347
|
-
}
|
348
|
-
|
349
|
-
if (argsReply[1] != "ok") {
|
350
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
351
|
-
P_WARN("The UstRouter sent an invalid reply message;" <<
|
352
|
-
" will reconnect in " << reconnectTimeout / 1000000 <<
|
353
|
-
" second(s).");
|
354
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
355
|
-
return false;
|
356
|
-
}
|
357
|
-
|
358
|
-
if (argsReply.size() < 2 + expectedExtraReplyArgs) {
|
359
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
360
|
-
P_WARN("The UstRouter sent an invalid reply message"
|
361
|
-
" (\"ok\" status message has too few arguments);" <<
|
362
|
-
" will reconnect in " << reconnectTimeout / 1000000 <<
|
363
|
-
" second(s).");
|
364
|
-
nextReconnectTime = SystemTime::getUsec() + reconnectTimeout;
|
365
|
-
return false;
|
366
|
-
}
|
367
|
-
|
368
|
-
guard.clear();
|
369
|
-
return true;
|
370
|
-
|
371
|
-
} catch (const TimeoutException &) {
|
372
|
-
handleTimeout();
|
373
|
-
return false;
|
374
|
-
} catch (const SystemException &e) {
|
375
|
-
handleNetworkErrorOrThrow(connection, guard, e);
|
376
|
-
return false;
|
377
|
-
}
|
378
|
-
}
|
379
|
-
|
380
|
-
TransactionPtr newTransaction(const string &groupName,
|
381
|
-
const string &category = "requests",
|
382
|
-
const string &unionStationKey = "-",
|
383
|
-
const string &filters = string())
|
384
|
-
{
|
385
|
-
if (isNull()) {
|
386
|
-
return createNullTransaction();
|
387
|
-
}
|
388
|
-
|
389
|
-
// Prepare parameters.
|
390
|
-
unsigned long long timestamp = SystemTime::getUsec();
|
391
|
-
char timestampStr[2 * sizeof(unsigned long long) + 1];
|
392
|
-
|
393
|
-
integerToHexatri<unsigned long long>(timestamp, timestampStr);
|
394
|
-
StaticString params[] = {
|
395
|
-
StaticString("openTransaction", sizeof("openTransaction") - 1),
|
396
|
-
// empty txnId, implies that it should be autogenerated by
|
397
|
-
// the UstRouter
|
398
|
-
StaticString(),
|
399
|
-
groupName,
|
400
|
-
// empty nodeName, implies using the default
|
401
|
-
// nodeName passed during initialization
|
402
|
-
StaticString(),
|
403
|
-
category,
|
404
|
-
timestampStr,
|
405
|
-
unionStationKey,
|
406
|
-
P_STATIC_STRING("true"), // crashProtect
|
407
|
-
P_STATIC_STRING("true"), // ack
|
408
|
-
filters
|
409
|
-
};
|
410
|
-
unsigned int nparams = sizeof(params) / sizeof(StaticString);
|
411
|
-
|
412
|
-
// Get a connection to the UstRouter.
|
413
|
-
ConnectionPtr connection = checkoutConnection();
|
414
|
-
if (connection == NULL) {
|
415
|
-
P_TRACE(2, "Created NULL Union Station transaction: group=" << groupName <<
|
416
|
-
", category=" << category);
|
417
|
-
return createNullTransaction();
|
418
|
-
}
|
419
|
-
|
420
|
-
// The router will generate a txnId for us and pass it in the response.
|
421
|
-
vector<string> argsReply;
|
422
|
-
if (sendRequestGetResponse(connection, params, nparams, argsReply, 1)) {
|
423
|
-
string txnId = argsReply[2];
|
424
|
-
ConnectionGuard guard(connection.get());
|
425
|
-
TransactionPtr transaction = boost::make_shared<Transaction>(
|
426
|
-
shared_from_this(),
|
427
|
-
connection,
|
428
|
-
txnId,
|
429
|
-
groupName,
|
430
|
-
category,
|
431
|
-
unionStationKey);
|
432
|
-
guard.clear();
|
433
|
-
P_TRACE(2, "Created new Union Station transaction: group=" << groupName <<
|
434
|
-
", category=" << category << ", txnId=" << txnId);
|
435
|
-
return transaction;
|
436
|
-
} else {
|
437
|
-
P_TRACE(2, "Created NULL Union Station transaction: group=" << groupName <<
|
438
|
-
", category=" << category);
|
439
|
-
return createNullTransaction();
|
440
|
-
}
|
441
|
-
}
|
442
|
-
|
443
|
-
TransactionPtr continueTransaction(const string &txnId,
|
444
|
-
const string &groupName,
|
445
|
-
const string &category = "requests",
|
446
|
-
const string &unionStationKey = "-")
|
447
|
-
{
|
448
|
-
if (isNull() || txnId.empty()) {
|
449
|
-
return createNullTransaction();
|
450
|
-
}
|
451
|
-
|
452
|
-
// Prepare parameters.
|
453
|
-
char timestampStr[2 * sizeof(unsigned long long) + 1];
|
454
|
-
integerToHexatri<unsigned long long>(SystemTime::getUsec(), timestampStr);
|
455
|
-
|
456
|
-
StaticString params[] = {
|
457
|
-
StaticString("openTransaction", sizeof("openTransaction") - 1),
|
458
|
-
txnId,
|
459
|
-
groupName,
|
460
|
-
// empty nodeName, implies using the default
|
461
|
-
// nodeName passed during initialization
|
462
|
-
StaticString(),
|
463
|
-
category,
|
464
|
-
timestampStr,
|
465
|
-
unionStationKey,
|
466
|
-
P_STATIC_STRING("true"), // crashProtect
|
467
|
-
P_STATIC_STRING("false") // ack
|
468
|
-
};
|
469
|
-
unsigned int nparams = sizeof(params) / sizeof(StaticString);
|
470
|
-
|
471
|
-
// Get a connection to the UstRouter.
|
472
|
-
ConnectionPtr connection = checkoutConnection();
|
473
|
-
if (connection == NULL) {
|
474
|
-
return createNullTransaction();
|
475
|
-
}
|
476
|
-
|
477
|
-
// We didn't ask for a response (ack), so just send here.
|
478
|
-
if (sendRequest(connection, params, nparams)) {
|
479
|
-
ConnectionGuard guard(connection.get());
|
480
|
-
TransactionPtr transaction = boost::make_shared<Transaction>(
|
481
|
-
shared_from_this(),
|
482
|
-
connection,
|
483
|
-
txnId,
|
484
|
-
groupName,
|
485
|
-
category,
|
486
|
-
unionStationKey);
|
487
|
-
guard.clear();
|
488
|
-
return transaction;
|
489
|
-
} else {
|
490
|
-
return createNullTransaction();
|
491
|
-
}
|
492
|
-
}
|
493
|
-
|
494
|
-
|
495
|
-
/***** Parameter getters and setters *****/
|
496
|
-
|
497
|
-
void setReconnectTimeout(unsigned long long usec) {
|
498
|
-
boost::lock_guard<boost::mutex> l(syncher);
|
499
|
-
reconnectTimeout = usec;
|
500
|
-
}
|
501
|
-
|
502
|
-
bool isNull() const {
|
503
|
-
return serverAddress.empty();
|
504
|
-
}
|
505
|
-
|
506
|
-
const string &getAddress() const {
|
507
|
-
return serverAddress;
|
508
|
-
}
|
509
|
-
|
510
|
-
const string &getUsername() const {
|
511
|
-
return username;
|
512
|
-
}
|
513
|
-
|
514
|
-
const string &getPassword() const {
|
515
|
-
return password;
|
516
|
-
}
|
517
|
-
|
518
|
-
/**
|
519
|
-
* @post !result.empty()
|
520
|
-
*/
|
521
|
-
const string &getNodeName() const {
|
522
|
-
return nodeName;
|
523
|
-
}
|
524
|
-
};
|
525
|
-
|
526
|
-
|
527
|
-
inline void
|
528
|
-
_checkinConnection(const ContextPtr &ctx, const ConnectionPtr &connection) {
|
529
|
-
ctx->checkinConnection(connection);
|
530
|
-
}
|
531
|
-
|
532
|
-
|
533
|
-
} // namespace UnionStation
|
534
|
-
} // namespace Passenger
|
535
|
-
|
536
|
-
#endif /* _PASSENGER_UNION_STATION_CONTEXT_H_ */
|