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,448 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
-
* Copyright (c) 2010-2017 Phusion
|
4
|
-
*
|
5
|
-
* "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
|
6
|
-
*
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
12
|
-
* furnished to do so, subject to the following conditions:
|
13
|
-
*
|
14
|
-
* The above copyright notice and this permission notice shall be included in
|
15
|
-
* all copies or substantial portions of the Software.
|
16
|
-
*
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
-
* THE SOFTWARE.
|
24
|
-
*/
|
25
|
-
|
26
|
-
var log;
|
27
|
-
var net = require('net');
|
28
|
-
var nbo = require('vendor-copy/network-byte-order');
|
29
|
-
var codify = require('vendor-copy/codify');
|
30
|
-
|
31
|
-
var ustRouterAddress; // will normally be a unix sock, although there is a default standalone = "tcp://127.0.0.1:9344";
|
32
|
-
var ustRouterPort; // if not a unix sock
|
33
|
-
var ustRouterUser;
|
34
|
-
var ustRouterPass;
|
35
|
-
var ustGatewayKey;
|
36
|
-
|
37
|
-
var appGroupName;
|
38
|
-
|
39
|
-
var routerConn;
|
40
|
-
var routerState;
|
41
|
-
// -1: disabled (not initialized or unrecoverable error, won't try to reconnect without new init)
|
42
|
-
// 0: disconnected, ready to (re)try connect
|
43
|
-
// 1: awaiting connect
|
44
|
-
// 2: awaiting version
|
45
|
-
// 3: awaiting auth OK
|
46
|
-
// 4: awaiting init OK
|
47
|
-
// 5: idle / ready to send
|
48
|
-
// 6: awaiting openTransaction OK
|
49
|
-
// 7: awaiting closeTransaction OK
|
50
|
-
|
51
|
-
var pendingTxnBuf;
|
52
|
-
var pendingTxnBufMaxLength;
|
53
|
-
var connTimeoutMs;
|
54
|
-
var autoRetryAfterMs;
|
55
|
-
|
56
|
-
setDefaults();
|
57
|
-
function setDefaults() {
|
58
|
-
routerState = -1;
|
59
|
-
pendingTxnBuf = [];
|
60
|
-
pendingTxnBufMaxLength = 5000;
|
61
|
-
connTimeoutMs = 10000;
|
62
|
-
autoRetryAfterMs = 30000;
|
63
|
-
}
|
64
|
-
|
65
|
-
// Call to initiate a connection with the UstRouter. If called with incomplete parameters the connector will just be
|
66
|
-
// disabled (isEnabled() will return false) and no further actions will be taken. If the connection fails, it is auto-retried
|
67
|
-
// whenever logToUstTransaction(..) is called.
|
68
|
-
exports.init = function(logger, routerAddress, routerUser, routerPass, gatewayKey, groupName) {
|
69
|
-
log = logger;
|
70
|
-
if (routerState > 0) {
|
71
|
-
log.warn("Trying to init when routerState > 0! (ignoring)");
|
72
|
-
return;
|
73
|
-
}
|
74
|
-
|
75
|
-
routerState = -1;
|
76
|
-
ustRouterAddress = routerAddress;
|
77
|
-
ustRouterUser = routerUser;
|
78
|
-
ustRouterPass = routerPass;
|
79
|
-
ustGatewayKey = gatewayKey;
|
80
|
-
appGroupName = groupName;
|
81
|
-
|
82
|
-
if (ustRouterAddress) {
|
83
|
-
if (ustRouterAddress.indexOf("unix:") == 0) {
|
84
|
-
// createConnection doesn't understand the "unix:" prefix, but it does understand the path that follows.
|
85
|
-
ustRouterAddress = ustRouterAddress.substring(5);
|
86
|
-
} else if (ustRouterAddress.indexOf("tcp://") == 0) {
|
87
|
-
var hostAndPort = ustRouterAddress.substring(6).split(':');
|
88
|
-
ustRouterAddress = hostAndPort[0];
|
89
|
-
ustRouterPort = hostAndPort[1];
|
90
|
-
}
|
91
|
-
}
|
92
|
-
log.debug("initialize ustrouter_connector with [routerAddress:" + ustRouterAddress + "] " +
|
93
|
-
(ustRouterPort ? "[ustRouterPort:" + ustRouterPort + "] " : "") + "[user:" + ustRouterUser + "] [pass:" +
|
94
|
-
ustRouterPass + "] [key:" + ustGatewayKey + "] [app:" + appGroupName + "]");
|
95
|
-
|
96
|
-
if (!ustRouterAddress || !ustRouterUser || !ustRouterPass || !ustGatewayKey || !appGroupName) {
|
97
|
-
log.verbose("Union Station logging disabled (incomplete configuration).");
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
|
101
|
-
changeState(0, "Init approved");
|
102
|
-
|
103
|
-
beginConnection();
|
104
|
-
};
|
105
|
-
|
106
|
-
exports.finit = function() {
|
107
|
-
resetState("finit()");
|
108
|
-
};
|
109
|
-
|
110
|
-
exports.isEnabled = function() {
|
111
|
-
return routerState >= 0;
|
112
|
-
};
|
113
|
-
|
114
|
-
function beginConnection() {
|
115
|
-
changeState(1);
|
116
|
-
|
117
|
-
setWatchdog(connTimeoutMs); // Watchdog for the entire connect-to-ustRouter process.
|
118
|
-
|
119
|
-
if (ustRouterPort) {
|
120
|
-
routerConn = net.createConnection(ustRouterPort, ustRouterAddress);
|
121
|
-
} else {
|
122
|
-
routerConn = net.createConnection(ustRouterAddress);
|
123
|
-
}
|
124
|
-
|
125
|
-
routerConn.on("connect", onConnect);
|
126
|
-
routerConn.on("error", onError);
|
127
|
-
routerConn.on("end", onEnd);
|
128
|
-
routerConn.on("data", onData);
|
129
|
-
}
|
130
|
-
|
131
|
-
function onConnect() {
|
132
|
-
changeState(2);
|
133
|
-
}
|
134
|
-
|
135
|
-
function onError(e) {
|
136
|
-
if (routerState == 1) {
|
137
|
-
log.error("Unable to connect to UstRouter at [" + ustRouterAddress +"], will auto-retry.");
|
138
|
-
} else {
|
139
|
-
// could be called when e.g. a write fails
|
140
|
-
log.error("Uncategorized error in UstRouter connection: " + e + ", will auto-retry.");
|
141
|
-
}
|
142
|
-
resetState("onError");
|
143
|
-
}
|
144
|
-
|
145
|
-
function onEnd() {
|
146
|
-
// e.g. when connection dies
|
147
|
-
resetState("onEnd");
|
148
|
-
}
|
149
|
-
|
150
|
-
function getWallclockMicrosec() {
|
151
|
-
// for lack of a more accurate clock
|
152
|
-
return new Date().getTime() * 1000;
|
153
|
-
}
|
154
|
-
|
155
|
-
function LogTransaction(cat) {
|
156
|
-
this.timestamp = getWallclockMicrosec();
|
157
|
-
this.category = cat;
|
158
|
-
this.txnId = "";
|
159
|
-
this.logBuf = [];
|
160
|
-
this.state = 0; // 0: untouched, 1: open sent, 2: close sent
|
161
|
-
}
|
162
|
-
|
163
|
-
function findLastPendingTxnForId(txnId) {
|
164
|
-
for (var i = pendingTxnBuf.length - 1; i >= 0; i--) {
|
165
|
-
if (pendingTxnBuf[i].txnId == txnId) {
|
166
|
-
return pendingTxnBuf[i];
|
167
|
-
}
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
exports.deferIfPendingTxns = function(txnId, deferThis, deferFn, deferArgs) {
|
172
|
-
var txn = findLastPendingTxnForId(txnId);
|
173
|
-
|
174
|
-
if (!txn) {
|
175
|
-
return deferFn.apply(deferThis, deferArgs);
|
176
|
-
} else {
|
177
|
-
log.debug("defer response.end() for txn " + txnId);
|
178
|
-
txn.deferThis = deferThis;
|
179
|
-
txn.deferFn = deferFn;
|
180
|
-
txn.deferArgs = deferArgs;
|
181
|
-
}
|
182
|
-
};
|
183
|
-
|
184
|
-
// Example categories are "requests", "exceptions". The lineArray is a specific format parsed by Union STation.
|
185
|
-
// txnIfContinue is an optional txnId and attaches the log to an existing transaction with the specified txnId.
|
186
|
-
// N.B. transactions will be dropped if the outgoing buffer limit is reached.
|
187
|
-
exports.logToUstTransaction = function(category, lineArray, txnIfContinue) {
|
188
|
-
if (!this.isEnabled()) {
|
189
|
-
return;
|
190
|
-
}
|
191
|
-
|
192
|
-
if (pendingTxnBuf.length < pendingTxnBufMaxLength) {
|
193
|
-
var logTxn = new LogTransaction(category);
|
194
|
-
|
195
|
-
if (txnIfContinue) {
|
196
|
-
logTxn.txnId = txnIfContinue;
|
197
|
-
}
|
198
|
-
logTxn.logBuf = lineArray;
|
199
|
-
|
200
|
-
pendingTxnBuf.push(logTxn);
|
201
|
-
} else {
|
202
|
-
log.debug("Dropping Union Station log due to outgoing buffer limit (" + pendingTxnBufMaxLength + ") reached");
|
203
|
-
}
|
204
|
-
|
205
|
-
pushPendingData();
|
206
|
-
};
|
207
|
-
|
208
|
-
function verifyOk(rcvString, topic) {
|
209
|
-
if ("status" != rcvString[0] || "ok" != rcvString[1]) {
|
210
|
-
log.error("Error with " + topic + ": [" + rcvString + "], will auto-retry.");
|
211
|
-
resetState("not OK reply");
|
212
|
-
return false;
|
213
|
-
}
|
214
|
-
return true;
|
215
|
-
}
|
216
|
-
|
217
|
-
function pushPendingData() {
|
218
|
-
log.debug("pushPendingData");
|
219
|
-
|
220
|
-
if (routerState == 0) {
|
221
|
-
// it disconnected or crashed somehow, reconnect
|
222
|
-
beginConnection();
|
223
|
-
return;
|
224
|
-
} else if (routerState != 5) {
|
225
|
-
return; // we're not ready to send
|
226
|
-
}
|
227
|
-
|
228
|
-
// we have an authenticated, active connection; see what we can send
|
229
|
-
if (pendingTxnBuf.length == 0) {
|
230
|
-
return; // no pending
|
231
|
-
}
|
232
|
-
|
233
|
-
switch (pendingTxnBuf[0].state) {
|
234
|
-
case 0:
|
235
|
-
// still need to open the txn
|
236
|
-
changeState(6); // expect ok/txnid in onData()..
|
237
|
-
setWatchdog(connTimeoutMs);
|
238
|
-
log.debug("open transaction(" + pendingTxnBuf[0].txnId + ")");
|
239
|
-
pendingTxnBuf[0].state = 1;
|
240
|
-
writeLenArray(routerConn, "openTransaction\0" + pendingTxnBuf[0].txnId + "\0" + appGroupName + "\0\0" +
|
241
|
-
pendingTxnBuf[0].category + "\0" + codify.toCode(pendingTxnBuf[0].timestamp) + "\0" + ustGatewayKey + "\0true\0true\0\0");
|
242
|
-
break;
|
243
|
-
|
244
|
-
case 1:
|
245
|
-
// open was sent, still waiting for OK.
|
246
|
-
break;
|
247
|
-
|
248
|
-
case 2:
|
249
|
-
// txn is open, log the data & close
|
250
|
-
log.debug("log & close transaction(" + pendingTxnBuf[0].txnId + ")");
|
251
|
-
var txn = pendingTxnBuf.shift();
|
252
|
-
|
253
|
-
if (txn.deferFn) {
|
254
|
-
var moveToTxn = findLastPendingTxnForId(txn.txnId);
|
255
|
-
if (!moveToTxn) {
|
256
|
-
log.debug("found deferred response.end(), no other queued attachments for txn " + txn.txnId + ", so calling now that it's safe");
|
257
|
-
txn.deferFn.apply(txn.deferThis, txn.deferArgs);
|
258
|
-
} else {
|
259
|
-
log.debug("moving deferred response.end() because there are other relevant attachment(s) for txn " + txn.txnId);
|
260
|
-
moveToTxn.deferThis = txn.deferThis;
|
261
|
-
moveToTxn.deferFn = txn.deferFn;
|
262
|
-
moveToTxn.deferArgs = txn.deferArgs;
|
263
|
-
}
|
264
|
-
}
|
265
|
-
|
266
|
-
for (var i = 0; i < txn.logBuf.length; i++) {
|
267
|
-
writeLenArray(routerConn, "log\0" + txn.txnId + "\0" + codify.toCode(txn.timestamp) + "\0");
|
268
|
-
writeLenString(routerConn, txn.logBuf[i]);
|
269
|
-
}
|
270
|
-
|
271
|
-
changeState(7); // expect ok in onData()..
|
272
|
-
setWatchdog(connTimeoutMs);
|
273
|
-
writeLenArray(routerConn, "closeTransaction\0" + txn.txnId + "\0" + codify.toCode(getWallclockMicrosec()) + "\0true\0");
|
274
|
-
log.debug("wrote log and close for " + txn.txnId);
|
275
|
-
break;
|
276
|
-
|
277
|
-
default:
|
278
|
-
log.error("Unexpected pendingTxnBuf[0].state " + pendingTxnBuf[0].state + ", discarding it.");
|
279
|
-
pendingTxnBuf.shift();
|
280
|
-
break;
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
var watchDogId;
|
285
|
-
|
286
|
-
function onWatchdogTimeout() {
|
287
|
-
resetState("onWatchdogTimeout");
|
288
|
-
}
|
289
|
-
|
290
|
-
// Resets the connection if there is no progress in the next timeoutMs.
|
291
|
-
function setWatchdog(timeoutMs) {
|
292
|
-
if (watchDogId) {
|
293
|
-
resetWatchdog();
|
294
|
-
}
|
295
|
-
watchDogId = setTimeout(onWatchdogTimeout, timeoutMs);
|
296
|
-
}
|
297
|
-
|
298
|
-
function resetWatchdog() {
|
299
|
-
if (watchDogId) {
|
300
|
-
clearTimeout(watchDogId);
|
301
|
-
watchDogId = null;
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
305
|
-
var readBuf = "";
|
306
|
-
// N.B. newData may be partial!
|
307
|
-
function readLenArray(newData) {
|
308
|
-
readBuf += newData;
|
309
|
-
log.silly("read: total len = " + readBuf.length);
|
310
|
-
log.silly(new Buffer(readBuf).toString("hex"));
|
311
|
-
|
312
|
-
if (readBuf.length < 2) {
|
313
|
-
log.silly("need more header data..");
|
314
|
-
return null; // expecting at least length bytes
|
315
|
-
}
|
316
|
-
|
317
|
-
var payloadLen = nbo.ntohs(new Buffer(readBuf), 0);
|
318
|
-
log.silly("read: payloadLen = " + payloadLen);
|
319
|
-
|
320
|
-
if (readBuf.length < 2 + payloadLen) {
|
321
|
-
log.silly("need more payload data..");
|
322
|
-
return null; // not fully read yet
|
323
|
-
}
|
324
|
-
var resultStr = readBuf.substring(2, payloadLen + 2);
|
325
|
-
readBuf = readBuf.substring(payloadLen + 2); // keep any bytes read beyond length for next read
|
326
|
-
|
327
|
-
return resultStr.split("\0");
|
328
|
-
}
|
329
|
-
|
330
|
-
function onData(data) {
|
331
|
-
log.silly("onData [" + data + "] (len = " + data.length + ")");
|
332
|
-
|
333
|
-
var rcvString = readLenArray(data);
|
334
|
-
if (!rcvString) {
|
335
|
-
return;
|
336
|
-
}
|
337
|
-
|
338
|
-
log.silly("got: [" + rcvString + "]");
|
339
|
-
|
340
|
-
switch (routerState) {
|
341
|
-
case 2:
|
342
|
-
if ("version" == rcvString[0] && "1" == rcvString[1]) {
|
343
|
-
changeState(3);
|
344
|
-
|
345
|
-
writeLenString(routerConn, ustRouterUser);
|
346
|
-
writeLenString(routerConn, ustRouterPass);
|
347
|
-
} else {
|
348
|
-
log.error("Error with UstRouter version: [" + rcvString + "], will auto-retry.");
|
349
|
-
resetState("not OK version reply");
|
350
|
-
}
|
351
|
-
break;
|
352
|
-
|
353
|
-
case 3:
|
354
|
-
if (verifyOk(rcvString, "UstRouter authentication")) {
|
355
|
-
changeState(4);
|
356
|
-
writeLenArray(routerConn, "init\0");
|
357
|
-
}
|
358
|
-
break;
|
359
|
-
|
360
|
-
case 4:
|
361
|
-
if (verifyOk(rcvString, "UstRouter initialization")) {
|
362
|
-
resetWatchdog(); // initialization done, lift the watchdog guard
|
363
|
-
changeState(5);
|
364
|
-
pushPendingData();
|
365
|
-
}
|
366
|
-
break;
|
367
|
-
|
368
|
-
case 5:
|
369
|
-
log.warn("unexpected data receive state (5)");
|
370
|
-
pushPendingData();
|
371
|
-
break;
|
372
|
-
|
373
|
-
case 6:
|
374
|
-
resetWatchdog();
|
375
|
-
if (verifyOk(rcvString, "UstRouter openTransaction")) {
|
376
|
-
pendingTxnBuf[0].state = 2;
|
377
|
-
if (pendingTxnBuf[0].txnId.length == 0) {
|
378
|
-
log.debug("use rcvd back txnId: " + rcvString[2]);
|
379
|
-
pendingTxnBuf[0].txnId = rcvString[2]; // fill in the txn from the UstRouter reply
|
380
|
-
}
|
381
|
-
|
382
|
-
changeState(5);
|
383
|
-
pushPendingData();
|
384
|
-
}
|
385
|
-
break;
|
386
|
-
|
387
|
-
case 7:
|
388
|
-
resetWatchdog();
|
389
|
-
if (verifyOk(rcvString, "UstRouter closeTransaction")) {
|
390
|
-
changeState(5);
|
391
|
-
pushPendingData();
|
392
|
-
}
|
393
|
-
break;
|
394
|
-
}
|
395
|
-
}
|
396
|
-
|
397
|
-
function resetState(reason) {
|
398
|
-
changeState(0, reason);
|
399
|
-
|
400
|
-
// When experiencing a mid-transaction failure (pending transaction state is increased once a transaction open has
|
401
|
-
// been sent), we don't really know what the other side remembers about the transaction (e.g. nothing if it crashed).
|
402
|
-
// It's even possible that the transaction itself is causing the problem (e.g. invalid category), so we choose to
|
403
|
-
// drop it and disconnect. The drop avoids getting stuck on invalid txns and the disconnect cleans up remote resources.
|
404
|
-
if (pendingTxnBuf.length > 0 && pendingTxnBuf[0].state != 0) {
|
405
|
-
log.debug("Mid-transaction (id: " + pendingTxnBuf[0].txnId + ") failure: drop/skipping Union Station log");
|
406
|
-
pendingTxnBuf.shift();
|
407
|
-
}
|
408
|
-
|
409
|
-
// ensure connection is finished and we don't get any outdated triggers
|
410
|
-
resetWatchdog();
|
411
|
-
|
412
|
-
if (routerConn) {
|
413
|
-
routerConn.destroy();
|
414
|
-
}
|
415
|
-
|
416
|
-
setTimeout(function() { pushPendingData(); }, autoRetryAfterMs);
|
417
|
-
}
|
418
|
-
|
419
|
-
function changeState(newRouterState, optReason) {
|
420
|
-
log.debug("routerState: " + routerState + " -> " + newRouterState + (optReason ? " due to: " + optReason : ""));
|
421
|
-
|
422
|
-
routerState = newRouterState;
|
423
|
-
}
|
424
|
-
|
425
|
-
function writeLenString(c, str) {
|
426
|
-
var len = new Buffer(4);
|
427
|
-
nbo.htonl(len, 0, str.length);
|
428
|
-
c.write(len);
|
429
|
-
c.write(str);
|
430
|
-
}
|
431
|
-
|
432
|
-
function writeLenArray(c, str) {
|
433
|
-
var len = new Buffer(2);
|
434
|
-
nbo.htons(len, 0, str.length);
|
435
|
-
c.write(len);
|
436
|
-
c.write(str);
|
437
|
-
}
|
438
|
-
|
439
|
-
if (process.env.NODE_ENV === 'test') {
|
440
|
-
exports.setDefaults = setDefaults;
|
441
|
-
exports.pushPendingData = pushPendingData;
|
442
|
-
|
443
|
-
exports.getRouterState = function() { return routerState; };
|
444
|
-
exports.setPendingTxnBufMaxLength = function(val) { pendingTxnBufMaxLength = val; };
|
445
|
-
exports.getPendingTxnBuf = function() { return pendingTxnBuf; };
|
446
|
-
exports.setConnTimeoutMs = function(val) { connTimeoutMs = val; };
|
447
|
-
exports.setAutoRetryAfterMs = function(val) { autoRetryAfterMs = val; };
|
448
|
-
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# Configuration keys
|
2
|
-
|
3
|
-
## `:union_station_key`
|
4
|
-
|
5
|
-
Default: automatically set by Passenger
|
6
|
-
|
7
|
-
## `:app_group_name`
|
8
|
-
|
9
|
-
Default: automatically set by Passenger
|
10
|
-
|
11
|
-
## `:ust_router_address`
|
12
|
-
|
13
|
-
Default: automatically set by Passenger
|
14
|
-
|
15
|
-
## `:ust_router_password`
|
16
|
-
|
17
|
-
Default: automatically set by Passenger
|
18
|
-
|
19
|
-
## `:node_name`
|
20
|
-
|
21
|
-
Default: current host name
|
22
|
-
|
23
|
-
## `:event_preprocessor`
|
24
|
-
|
25
|
-
Default: none
|
26
|
-
|
27
|
-
## `:debug`
|
28
|
-
|
29
|
-
Default: false
|
30
|
-
|
31
|
-
Whether to print debugging messages for `union_station_hooks_*` gems.
|
32
|
-
|
33
|
-
## `:check_initialized`
|
34
|
-
|
35
|
-
Default: true
|
36
|
-
|
37
|
-
If enabled, and Union Station support in Passenger is enabled too, then Passenger will complain during application startup if the application never called `UnionStationHooks.initialize!`.
|