@rocket.chat/houston 0.27.0-next.2 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
package/dist/lib/lock.js
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LOCK_ORDER = exports.TRANSITION_NAME = exports.THIS_ROUTE = exports.DISPATCH_ROUTE_ENV = exports.DISPATCH_TABLE_ENV = exports.DUAL_IMPLEMENTATION = exports.THIS_IMPLEMENTATION = exports.MARKER_NAME = void 0;
|
|
37
|
+
exports.consumeDispatch = consumeDispatch;
|
|
38
|
+
exports.markerPath = markerPath;
|
|
39
|
+
exports.readImplementation = readImplementation;
|
|
40
|
+
exports.homeIsEmpty = homeIsEmpty;
|
|
41
|
+
exports.claim = claim;
|
|
42
|
+
exports.conflictReason = conflictReason;
|
|
43
|
+
exports.requireThisImplementation = requireThisImplementation;
|
|
44
|
+
exports.transitionPath = transitionPath;
|
|
45
|
+
exports.readTransition = readTransition;
|
|
46
|
+
exports.transitionReason = transitionReason;
|
|
47
|
+
exports.beginTransition = beginTransition;
|
|
48
|
+
exports.clearTransition = clearTransition;
|
|
49
|
+
exports.fsyncDir = fsyncDir;
|
|
50
|
+
exports.writeMarker = writeMarker;
|
|
51
|
+
/**
|
|
52
|
+
* Two builds must exclude each other from one state directory.
|
|
53
|
+
*
|
|
54
|
+
* This module is deliberately SMALLER than the lock module of earlier releases, and that
|
|
55
|
+
* difference is the subject of this comment.
|
|
56
|
+
*
|
|
57
|
+
* That module does two things: it owns the `~/.houston/IMPLEMENTATION`
|
|
58
|
+
* marker, and it adds an OFD write lock beside each of the five `flock` sites. The second
|
|
59
|
+
* half exists because of a measurement: `flock` and Linux OFD locks do NOT exclude each
|
|
60
|
+
* other, so a `flock` holder does not block an OFD acquirer.
|
|
61
|
+
*
|
|
62
|
+
* lock held by A B takes flock B takes OFD
|
|
63
|
+
* flock only BLOCKED ACQUIRED <- walks straight through
|
|
64
|
+
* OFD only ACQUIRED BLOCKED <- and so does this
|
|
65
|
+
* flock + additive OFD BLOCKED BLOCKED <- the fix
|
|
66
|
+
*
|
|
67
|
+
* **This module takes no file lock, and that is a measured decision rather than an
|
|
68
|
+
* omission.** Node has no built-in `flock`, and the native addon that would provide
|
|
69
|
+
* one is ruled out: `fs-ext` ships no prebuilt binary for any platform, so it compiles
|
|
70
|
+
* against the ABI of whichever Node installed it. It loads on Node 24 or on
|
|
71
|
+
* Node 26 and never both from one `node_modules`, which collides head-on with this
|
|
72
|
+
* project's own two-major test matrix, and it does not install on a stock musl image at
|
|
73
|
+
* all. Making the one mechanism whose entire job is preventing silent corruption into
|
|
74
|
+
* an ABI-pinned, per-platform, compiled dependency buys a lock and pays for it with a
|
|
75
|
+
* new class of hard failure. The cross-process lock is `seams/fs/lock.ts`'s instead,
|
|
76
|
+
* taken by a `flock(1)` child process.
|
|
77
|
+
*
|
|
78
|
+
* **So the marker carries the whole weight here:** the `~/.houston/IMPLEMENTATION`
|
|
79
|
+
* marker is the dual-run safety mechanism, not the lock, and the additive OFD lock is
|
|
80
|
+
* defence in depth. This build keeps the marker exactly as earlier releases implement it
|
|
81
|
+
* -- same file, same names, same `O_EXCL` claim, same refusal text -- and adds no OFD lock
|
|
82
|
+
* of its own.
|
|
83
|
+
*
|
|
84
|
+
* **The consequence, stated rather than discovered:** an exclusive marker is what makes
|
|
85
|
+
* a foreign build fail loudly. `dual-v1` must not be promoted on the strength of a lock
|
|
86
|
+
* this build does not have; an interoperability test has to test the MARKER's refusal as
|
|
87
|
+
* the primary mechanism.
|
|
88
|
+
*
|
|
89
|
+
* **This module imports nothing but `errors` and two rank-0 leaves, `mkdir-parents` and
|
|
90
|
+
* `home`.** It is pure mechanism -- no policy, no configuration. That is what keeps
|
|
91
|
+
* `config.ts`, which is one of the lock sites, able to import it without a sideways or
|
|
92
|
+
* upward edge.
|
|
93
|
+
*/
|
|
94
|
+
const fs = __importStar(require("fs"));
|
|
95
|
+
const path = __importStar(require("path"));
|
|
96
|
+
const errors_1 = require("./errors");
|
|
97
|
+
const home_1 = require("./home");
|
|
98
|
+
const mkdir_parents_1 = require("./mkdir-parents");
|
|
99
|
+
/** The file that records which build last wrote a home. */
|
|
100
|
+
exports.MARKER_NAME = 'IMPLEMENTATION';
|
|
101
|
+
/**
|
|
102
|
+
* What THIS build calls itself.
|
|
103
|
+
*
|
|
104
|
+
* The marker value earlier releases write is another name. This must differ from it, or
|
|
105
|
+
* the whole mechanism is a no-op: the refusal is triggered by finding a name that is
|
|
106
|
+
* neither this build's nor `dual-v1`.
|
|
107
|
+
*/
|
|
108
|
+
exports.THIS_IMPLEMENTATION = 'typescript';
|
|
109
|
+
/**
|
|
110
|
+
* The marker value that meant "both builds have been cleared to share this home", and now
|
|
111
|
+
* means the home's state formats were validated by the build that ships (and by an earlier
|
|
112
|
+
* release too, when a peer validator is configured). Kept on write for the marker window: a
|
|
113
|
+
* fresh home is claimed with it, so an earlier release and an older build never race this
|
|
114
|
+
* one for a home, and a home carrying the earlier releases' marker is promoted to it once
|
|
115
|
+
* it is read back.
|
|
116
|
+
*/
|
|
117
|
+
exports.DUAL_IMPLEMENTATION = 'dual-v1';
|
|
118
|
+
/**
|
|
119
|
+
* What a launcher that routed commands between two builds set to `mixed` when it sent them
|
|
120
|
+
* to BOTH and to `single` when it sent them all to one. `bin/houston` is this build's entry
|
|
121
|
+
* and sets neither variable, so every run is `direct`; the two are still read and
|
|
122
|
+
* forgotten, because a process that inherits stale values must not act on them. Nothing
|
|
123
|
+
* acts on the table's value: a fresh home is `dual-v1` whatever it says.
|
|
124
|
+
*/
|
|
125
|
+
exports.DISPATCH_TABLE_ENV = 'HOUSTON_DISPATCHED_TABLE';
|
|
126
|
+
/**
|
|
127
|
+
* The route such a launcher exec'd, `py` or `ts`. A build that found its OWN route here was
|
|
128
|
+
* dispatched, and the event log records that as `via`; `bin/houston` sets none, so every
|
|
129
|
+
* run records `direct`.
|
|
130
|
+
*/
|
|
131
|
+
exports.DISPATCH_ROUTE_ENV = 'HOUSTON_DISPATCHED_ROUTE';
|
|
132
|
+
/** What a two-build routing table called this build. */
|
|
133
|
+
exports.THIS_ROUTE = 'ts';
|
|
134
|
+
/**
|
|
135
|
+
* How this process was started -- `dispatcher` or `direct` -- and the launcher's variables
|
|
136
|
+
* forgotten. Both variables describe THIS exec and nothing after it: a subprocess this
|
|
137
|
+
* build starts was not dispatched, and must not claim a home for both builds on the
|
|
138
|
+
* strength of a table it never saw. The entry point calls this once, after the home is
|
|
139
|
+
* claimed.
|
|
140
|
+
*/
|
|
141
|
+
function consumeDispatch() {
|
|
142
|
+
const route = process.env[exports.DISPATCH_ROUTE_ENV];
|
|
143
|
+
delete process.env[exports.DISPATCH_ROUTE_ENV];
|
|
144
|
+
delete process.env[exports.DISPATCH_TABLE_ENV];
|
|
145
|
+
return route === exports.THIS_ROUTE ? 'dispatcher' : 'direct';
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The marker's path in `home`. Joined component by component (`joinPath`), keeping a
|
|
149
|
+
* `..` as written, because `path.join` folds a `..` in the home against the text before
|
|
150
|
+
* it: `link/../hh` claimed `hh` in the working directory while earlier releases claimed
|
|
151
|
+
* the `other/hh` the kernel resolves, so each marked a directory the other never looked in.
|
|
152
|
+
*/
|
|
153
|
+
function markerPath(home) {
|
|
154
|
+
return (0, home_1.joinPath)(home, exports.MARKER_NAME);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Which build last wrote this home, or null if it has never been claimed.
|
|
158
|
+
*
|
|
159
|
+
* NEVER THROWS. A missing, unreadable, empty or uninterpretable marker returns null;
|
|
160
|
+
* `requireThisImplementation` distinguishes a genuinely absent path by attempting an
|
|
161
|
+
* exclusive claim. If a path exists but cannot be interpreted, that claim fails and the
|
|
162
|
+
* command refuses without overwriting evidence.
|
|
163
|
+
*/
|
|
164
|
+
function readImplementation(home) {
|
|
165
|
+
let text;
|
|
166
|
+
try {
|
|
167
|
+
// STRICT decoding: bytes that are not UTF-8 are an unreadable marker (null, and the
|
|
168
|
+
// claim then refuses), never a name. Node's 'utf8' substitutes U+FFFD, which turned
|
|
169
|
+
// them into a build called '��...'.
|
|
170
|
+
// `ignoreBOM` keeps a BOM in the text, as earlier releases read it.
|
|
171
|
+
text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(fs.readFileSync(markerPath(home)));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
// `stripText` and `firstTextLine`, not `trim()` and `split('\n')`: `trim()` also strips
|
|
177
|
+
// U+FEFF, so a marker saved with a BOM read as the earlier releases' marker here and as
|
|
178
|
+
// an unknown build to them -- the one file both builds must read identically. Local
|
|
179
|
+
// rather than `format`'s, because this module imports nothing but `errors`.
|
|
180
|
+
const stripped = stripText(text);
|
|
181
|
+
if (stripped === '')
|
|
182
|
+
return null;
|
|
183
|
+
const name = stripText(firstTextLine(stripped)).toLowerCase();
|
|
184
|
+
return name || null;
|
|
185
|
+
}
|
|
186
|
+
/** The whitespace `stripText` removes, as code points, not a regex. */
|
|
187
|
+
const SPACE_CHARS = new Set([
|
|
188
|
+
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x85, 0xa0, 0x1680, 0x2000, 0x2001,
|
|
189
|
+
0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x2028, 0x2029, 0x202f,
|
|
190
|
+
0x205f, 0x3000,
|
|
191
|
+
].map((point) => String.fromCodePoint(point)));
|
|
192
|
+
/** The single characters a line ends at; `\r\n` is one boundary. */
|
|
193
|
+
const LINE_ENDS = new Set([0x0a, 0x0b, 0x0c, 0x0d, 0x1c, 0x1d, 0x1e, 0x85, 0x2028, 0x2029].map((point) => String.fromCodePoint(point)));
|
|
194
|
+
/** The first line: the text up to the first line boundary. */
|
|
195
|
+
function firstTextLine(text) {
|
|
196
|
+
let end = 0;
|
|
197
|
+
while (end < text.length && !LINE_ENDS.has(text[end]))
|
|
198
|
+
end += 1;
|
|
199
|
+
return text.slice(0, end);
|
|
200
|
+
}
|
|
201
|
+
function stripText(text) {
|
|
202
|
+
let start = 0;
|
|
203
|
+
let end = text.length;
|
|
204
|
+
while (start < end && SPACE_CHARS.has(text[start]))
|
|
205
|
+
start += 1;
|
|
206
|
+
while (end > start && SPACE_CHARS.has(text[end - 1]))
|
|
207
|
+
end -= 1;
|
|
208
|
+
return text.slice(start, end);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Whether `home` holds nothing at all -- it does not exist, or it is an empty directory. A
|
|
212
|
+
* path that cannot be listed, or is not a directory, is NOT empty.
|
|
213
|
+
*/
|
|
214
|
+
function homeIsEmpty(home) {
|
|
215
|
+
try {
|
|
216
|
+
return fs.readdirSync(home).length === 0;
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
return err.code === 'ENOENT';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Atomically claim an unclaimed home and return the marker now present.
|
|
224
|
+
*
|
|
225
|
+
* `wx` is `O_WRONLY | O_CREAT | O_EXCL`, which closes the check-then-write race between
|
|
226
|
+
* two implementations starting against a fresh home. Existing markers are never
|
|
227
|
+
* overwritten, including `dual-v1`. Null means the marker could not be created or read
|
|
228
|
+
* safely. `value` is this build's own name, or `dual-v1` for an empty home, which is claimed
|
|
229
|
+
* for both builds.
|
|
230
|
+
*/
|
|
231
|
+
function claim(home, value = exports.THIS_IMPLEMENTATION) {
|
|
232
|
+
const found = readImplementation(home);
|
|
233
|
+
if (found !== null)
|
|
234
|
+
return found;
|
|
235
|
+
const target = markerPath(home);
|
|
236
|
+
let fd;
|
|
237
|
+
try {
|
|
238
|
+
// The home made with its parents: 0700 on the home alone, and the umask's mode on any
|
|
239
|
+
// parent it has to make, which a recursive mkdir would also have made 0700.
|
|
240
|
+
(0, mkdir_parents_1.mkdirParents)(path.dirname(target), 0o700);
|
|
241
|
+
fd = fs.openSync(target, 'wx', 0o600);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
if (err.code === 'EEXIST')
|
|
245
|
+
return readImplementation(home);
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
fs.writeFileSync(fd, `${value}\n`, 'utf8');
|
|
250
|
+
fs.fsyncSync(fd);
|
|
251
|
+
fs.closeSync(fd);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
try {
|
|
255
|
+
fs.closeSync(fd);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
/* already closed */
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
fs.unlinkSync(target);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
/* already gone */
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return value;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* A ready-to-raise explanation if this home belongs to another build, else null.
|
|
272
|
+
*
|
|
273
|
+
* The message is here rather than at the call site because it is the same message
|
|
274
|
+
* wherever it is raised, and because this module is the only place that knows what the
|
|
275
|
+
* marker means.
|
|
276
|
+
*/
|
|
277
|
+
function conflictReason(home) {
|
|
278
|
+
const found = readImplementation(home);
|
|
279
|
+
if (found === null || found === exports.THIS_IMPLEMENTATION || found === exports.DUAL_IMPLEMENTATION) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
return (`${markerPath(home)} says this state directory was last written by the ` +
|
|
283
|
+
`'${found}' build of houston, and this is the '${exports.THIS_IMPLEMENTATION}' build. ` +
|
|
284
|
+
'They do not share state safely: the two do not lock each other out of a ' +
|
|
285
|
+
'workspace, so running both against one home races docker compose against ' +
|
|
286
|
+
`itself and orphans containers no tool can then see. Use the '${found}' build ` +
|
|
287
|
+
'for this home, or give this build its own: export HOUSTON_HOME=<a new path>.');
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Refuse a home the other build owns; claim it otherwise.
|
|
291
|
+
*
|
|
292
|
+
* The policy lives here, beside the mechanism, rather than at the call site: this
|
|
293
|
+
* module is the only thing that knows what the marker means, and a second caller must
|
|
294
|
+
* not have to restate the reasoning to get the same refusal.
|
|
295
|
+
*/
|
|
296
|
+
function requireThisImplementation(home) {
|
|
297
|
+
// FAIL CLOSED, and BEFORE the ownership question. A promotion in flight is holding all
|
|
298
|
+
// five state locks and validating this home; a command that got past here would write
|
|
299
|
+
// to it and invalidate the check the new marker is about to be based on. It is checked
|
|
300
|
+
// first because it is true regardless of who owns the home -- including when THIS build
|
|
301
|
+
// owns it, which is the case an ownership-first order would wave through.
|
|
302
|
+
const inFlight = transitionReason(home);
|
|
303
|
+
if (inFlight)
|
|
304
|
+
throw new errors_1.PreflightError(inFlight);
|
|
305
|
+
const reason = conflictReason(home);
|
|
306
|
+
if (reason)
|
|
307
|
+
throw new errors_1.PreflightError(reason);
|
|
308
|
+
const found = readImplementation(home);
|
|
309
|
+
if (found === exports.DUAL_IMPLEMENTATION)
|
|
310
|
+
return;
|
|
311
|
+
// A FRESH HOME IS CLAIMED FOR BOTH, exactly as earlier releases do. `dual-v1`
|
|
312
|
+
// says every state format in the home was read by both builds and they agreed, and an
|
|
313
|
+
// EMPTY home has no format to disagree about. `dual-v1` is kept on write for the marker
|
|
314
|
+
// window: a fresh home is claimed for both whatever `HOUSTON_DISPATCHED_TABLE` says, so an
|
|
315
|
+
// earlier release and an older build never race this one for it. A home
|
|
316
|
+
// with anything in it and no marker is still claimed for this build alone.
|
|
317
|
+
const freshForBoth = found === null && homeIsEmpty(home);
|
|
318
|
+
const claimed = claim(home, freshForBoth ? exports.DUAL_IMPLEMENTATION : exports.THIS_IMPLEMENTATION);
|
|
319
|
+
if (claimed === exports.THIS_IMPLEMENTATION)
|
|
320
|
+
return;
|
|
321
|
+
if (claimed === exports.DUAL_IMPLEMENTATION)
|
|
322
|
+
return;
|
|
323
|
+
if (claimed) {
|
|
324
|
+
throw new errors_1.PreflightError(conflictReason(home) ?? `${markerPath(home)} was claimed by '${claimed}'`);
|
|
325
|
+
}
|
|
326
|
+
throw new errors_1.PreflightError(`cannot safely claim ${markerPath(home)} for this build. Check that ` +
|
|
327
|
+
'HOUSTON_HOME is writable and that its IMPLEMENTATION marker is readable.');
|
|
328
|
+
}
|
|
329
|
+
// ---------------------------------------------------------------- the promotion journal
|
|
330
|
+
//
|
|
331
|
+
// The transition journal, the same file and protocol as earlier releases use. The earlier
|
|
332
|
+
// releases' marker and `typescript` are EXCLUSIVE owners; `dual-v1` says the state formats
|
|
333
|
+
// in this home have been validated by both builds. Getting from one to the other is a
|
|
334
|
+
// migration, and a migration that can be interrupted needs a record that says so --
|
|
335
|
+
// otherwise a kill between "validated" and "marker replaced" leaves a home nobody can
|
|
336
|
+
// classify.
|
|
337
|
+
//
|
|
338
|
+
// So promotion writes a JOURNAL first and removes it last, and every normal command in
|
|
339
|
+
// BOTH builds refuses while it exists. The three states a kill can leave are all
|
|
340
|
+
// explainable; a changed marker with no explanation is not reachable.
|
|
341
|
+
/**
|
|
342
|
+
* The journal that says a promotion is in flight.
|
|
343
|
+
*
|
|
344
|
+
* A SIBLING of the marker, not a rewrite of it: the marker keeps saying who owns the
|
|
345
|
+
* home until the swap actually happens, so an interrupted promotion degrades to "still
|
|
346
|
+
* exclusive" rather than to "unknown".
|
|
347
|
+
*/
|
|
348
|
+
exports.TRANSITION_NAME = 'IMPLEMENTATION.transition';
|
|
349
|
+
/**
|
|
350
|
+
* The order the five state locks are taken in, by the path each names under the home.
|
|
351
|
+
*
|
|
352
|
+
* FIXED, and the same list earlier releases hold, because two builds taking
|
|
353
|
+
* the same five locks in two different orders is a deadlock that only appears under
|
|
354
|
+
* contention -- the one kind of bug a test on a quiet box does not find. The runner's lock
|
|
355
|
+
* is per workspace and expands, in sorted name order, at the position shown.
|
|
356
|
+
*/
|
|
357
|
+
exports.LOCK_ORDER = [
|
|
358
|
+
'.config.lock',
|
|
359
|
+
'locks/users.lock',
|
|
360
|
+
'locks/sessions.lock',
|
|
361
|
+
'logs/houston.log',
|
|
362
|
+
'locks/<workspace>.lock',
|
|
363
|
+
];
|
|
364
|
+
/** The journal's path in `home`, joined as `markerPath` is and for its reason. */
|
|
365
|
+
function transitionPath(home) {
|
|
366
|
+
return (0, home_1.joinPath)(home, exports.TRANSITION_NAME);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The in-flight promotion record, or null. Never throws.
|
|
370
|
+
*
|
|
371
|
+
* A journal that exists but cannot be parsed still counts as in flight and comes back as
|
|
372
|
+
* an empty record: the file's PRESENCE is the fail-closed signal, and a corrupt one must
|
|
373
|
+
* not read as "nothing is happening".
|
|
374
|
+
*
|
|
375
|
+
* So only a path that is NOT THERE is null -- and "there" means what `wx` in
|
|
376
|
+
* `beginTransition` means, a directory entry, which a dangling symlink is. Every other
|
|
377
|
+
* failure to read one counts as in flight. This used to return null for ANY read error, so
|
|
378
|
+
* a journal that was a directory or unreadable let every command in both builds through,
|
|
379
|
+
* and earlier releases let a non-UTF-8 one through that this build refused. Decoding is
|
|
380
|
+
* STRICT, as theirs is, so a record that is not UTF-8 is `{}` in both rather
|
|
381
|
+
* than a `started_by` of U+FFFD here and "another process" there.
|
|
382
|
+
*/
|
|
383
|
+
function readTransition(home) {
|
|
384
|
+
const target = transitionPath(home);
|
|
385
|
+
let text;
|
|
386
|
+
try {
|
|
387
|
+
text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(fs.readFileSync(target));
|
|
388
|
+
}
|
|
389
|
+
catch (err) {
|
|
390
|
+
const code = err.code;
|
|
391
|
+
if (code !== 'ENOENT' && code !== 'ENOTDIR')
|
|
392
|
+
return {};
|
|
393
|
+
try {
|
|
394
|
+
fs.lstatSync(target);
|
|
395
|
+
return {};
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
const parsed = JSON.parse(text);
|
|
403
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
404
|
+
? parsed
|
|
405
|
+
: {};
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
return {};
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Why a normal command must refuse right now, or null.
|
|
413
|
+
*
|
|
414
|
+
* Both builds refuse while a promotion is in flight, and for the same reason: the home is
|
|
415
|
+
* momentarily being validated under all five locks, and a write now would invalidate the
|
|
416
|
+
* check the new marker is about to be based on.
|
|
417
|
+
*/
|
|
418
|
+
function transitionReason(home) {
|
|
419
|
+
const record = readTransition(home);
|
|
420
|
+
if (record === null)
|
|
421
|
+
return null;
|
|
422
|
+
const startedBy = typeof record.started_by === 'string' && record.started_by !== ''
|
|
423
|
+
? record.started_by
|
|
424
|
+
: 'another process';
|
|
425
|
+
return (`${transitionPath(home)} says a promotion to '${exports.DUAL_IMPLEMENTATION}' is in ` +
|
|
426
|
+
`flight, started by '${startedBy}'. Every command refuses while it exists, ` +
|
|
427
|
+
'because the promotion validates this home under all five state locks and a ' +
|
|
428
|
+
'write now would invalidate the check the new marker is based on. If no ' +
|
|
429
|
+
'promotion is actually running, it was interrupted: remove that file and run the ' +
|
|
430
|
+
'command again. The marker was not touched, so the next run validates the home ' +
|
|
431
|
+
'from scratch (a marker already at the target means only this cleanup was lost).');
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Create the journal atomically, leaving the marker alone. False if one already exists.
|
|
435
|
+
*
|
|
436
|
+
* `wx` is what makes two concurrent promotions impossible: the loser sees the file and
|
|
437
|
+
* stops, rather than both proceeding to validate and swap.
|
|
438
|
+
*/
|
|
439
|
+
function beginTransition(home, record) {
|
|
440
|
+
const target = transitionPath(home);
|
|
441
|
+
let fd;
|
|
442
|
+
try {
|
|
443
|
+
(0, mkdir_parents_1.mkdirParents)(path.dirname(target), 0o700); // leaf-only, as `claim`
|
|
444
|
+
fd = fs.openSync(target, 'wx', 0o600);
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
if (err.code === 'EEXIST')
|
|
448
|
+
return false;
|
|
449
|
+
throw err;
|
|
450
|
+
}
|
|
451
|
+
try {
|
|
452
|
+
fs.writeFileSync(fd, `${JSON.stringify(record, Object.keys(record).sort())}\n`, 'utf8');
|
|
453
|
+
fs.fsyncSync(fd);
|
|
454
|
+
}
|
|
455
|
+
finally {
|
|
456
|
+
fs.closeSync(fd);
|
|
457
|
+
}
|
|
458
|
+
fsyncDir(home);
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
/** Remove the journal and fsync the directory. The LAST step of a promotion. */
|
|
462
|
+
function clearTransition(home) {
|
|
463
|
+
try {
|
|
464
|
+
fs.unlinkSync(transitionPath(home));
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
fsyncDir(home);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Durably record a rename or unlink in the CONTAINING directory.
|
|
473
|
+
*
|
|
474
|
+
* Without this the marker's new contents can be on disk while the directory entry
|
|
475
|
+
* pointing at them is not, which after a power loss is the half-promoted home the
|
|
476
|
+
* journal exists to make impossible.
|
|
477
|
+
*/
|
|
478
|
+
function fsyncDir(directory) {
|
|
479
|
+
let fd;
|
|
480
|
+
try {
|
|
481
|
+
fd = fs.openSync(directory, 'r');
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
fs.fsyncSync(fd);
|
|
488
|
+
}
|
|
489
|
+
catch {
|
|
490
|
+
/* not supported on this filesystem */
|
|
491
|
+
}
|
|
492
|
+
finally {
|
|
493
|
+
fs.closeSync(fd);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Replace the marker atomically with `value`, then fsync the directory.
|
|
498
|
+
*
|
|
499
|
+
* Temp-then-rename, because a truncate-and-write leaves a window in which the marker is
|
|
500
|
+
* empty -- and an empty marker reads as "never claimed", which is the one answer that
|
|
501
|
+
* lets the wrong build claim the home.
|
|
502
|
+
*/
|
|
503
|
+
function writeMarker(home, value) {
|
|
504
|
+
const target = markerPath(home);
|
|
505
|
+
const tmp = `${target}.${String(process.pid)}.tmp`;
|
|
506
|
+
const fd = fs.openSync(tmp, 'w', 0o600);
|
|
507
|
+
try {
|
|
508
|
+
fs.writeFileSync(fd, `${value}\n`, 'utf8');
|
|
509
|
+
fs.fsyncSync(fd);
|
|
510
|
+
}
|
|
511
|
+
finally {
|
|
512
|
+
fs.closeSync(fd);
|
|
513
|
+
}
|
|
514
|
+
fs.renameSync(tmp, target);
|
|
515
|
+
fsyncDir(home);
|
|
516
|
+
}
|