@harperfast/harper 5.2.9 → 5.3.0-alpha.1
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/agent/mcpTools.ts +1 -1
- package/agent/session.ts +25 -14
- package/bin/cliOperations.ts +46 -9
- package/bin/copyDb.ts +282 -59
- package/bin/deploySetup.ts +16 -5
- package/bin/harper.ts +1 -1
- package/bin/help.ts +4 -1
- package/bin/lite.ts +4 -1
- package/bin/restart.ts +59 -3
- package/bin/run.ts +6 -11
- package/bin/upgrade.js +7 -3
- package/bin/workloadIdentity.ts +119 -0
- package/components/Application.ts +2414 -242
- package/components/ApplicationScope.ts +8 -0
- package/components/EntryHandler.ts +59 -39
- package/components/OptionsWatcher.ts +150 -74
- package/components/RuntimeModuleTracker.ts +38 -7
- package/components/Scope.ts +37 -15
- package/components/awaitRestart.ts +84 -0
- package/components/componentLoader.ts +340 -30
- package/components/componentPreparationLock.ts +16 -5
- package/components/mcp/adapters/harperHttp.ts +4 -0
- package/components/mcp/listChanged.ts +4 -0
- package/components/mcp/toolRegistry.ts +2 -0
- package/components/mcp/tools/operations.ts +9 -0
- package/components/mcp/tools/schemas/operationDescriptions.ts +2 -2
- package/components/operations.js +270 -78
- package/components/operationsValidation.js +49 -1
- package/components/status/ComponentStatusRegistry.ts +59 -0
- package/config/RootConfigWatcher.ts +80 -34
- package/config/configUtils.ts +291 -34
- package/config/harperConfigEnvVars.ts +170 -27
- package/config-root.schema.json +29 -0
- package/dataLayer/blobBackup.ts +160 -50
- package/dataLayer/delete.ts +6 -1
- package/dataLayer/harperBridge/ResourceBridge.ts +52 -8
- package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +3 -1
- package/dataLayer/hdbInfoController.ts +34 -1
- package/dataLayer/insert.ts +44 -1
- package/dataLayer/rocksdbBackup.ts +53 -10
- package/dataLayer/schema.ts +11 -1
- package/dataLayer/schemaDescribe.ts +8 -1
- package/dist/agent/mcpTools.js +1 -1
- package/dist/agent/mcpTools.js.map +1 -1
- package/dist/agent/session.d.ts +22 -0
- package/dist/agent/session.js +26 -15
- package/dist/agent/session.js.map +1 -1
- package/dist/bin/cliOperations.js +48 -9
- package/dist/bin/cliOperations.js.map +1 -1
- package/dist/bin/copyDb.d.ts +12 -1
- package/dist/bin/copyDb.js +248 -60
- package/dist/bin/copyDb.js.map +1 -1
- package/dist/bin/deploySetup.d.ts +2 -0
- package/dist/bin/deploySetup.js +11 -3
- package/dist/bin/deploySetup.js.map +1 -1
- package/dist/bin/harper.js +1 -1
- package/dist/bin/harper.js.map +1 -1
- package/dist/bin/help.js +4 -1
- package/dist/bin/help.js.map +1 -1
- package/dist/bin/lite.js +4 -1
- package/dist/bin/lite.js.map +1 -1
- package/dist/bin/restart.js +54 -5
- package/dist/bin/restart.js.map +1 -1
- package/dist/bin/run.js +4 -10
- package/dist/bin/run.js.map +1 -1
- package/dist/bin/upgrade.js +4 -3
- package/dist/bin/upgrade.js.map +1 -1
- package/dist/bin/workloadIdentity.d.ts +18 -0
- package/dist/bin/workloadIdentity.js +100 -0
- package/dist/bin/workloadIdentity.js.map +1 -0
- package/dist/components/Application.d.ts +139 -16
- package/dist/components/Application.js +2215 -267
- package/dist/components/Application.js.map +1 -1
- package/dist/components/ApplicationScope.d.ts +8 -0
- package/dist/components/ApplicationScope.js +7 -0
- package/dist/components/ApplicationScope.js.map +1 -1
- package/dist/components/EntryHandler.js +26 -10
- package/dist/components/EntryHandler.js.map +1 -1
- package/dist/components/OptionsWatcher.d.ts +1 -0
- package/dist/components/OptionsWatcher.js +141 -74
- package/dist/components/OptionsWatcher.js.map +1 -1
- package/dist/components/RuntimeModuleTracker.js +40 -6
- package/dist/components/RuntimeModuleTracker.js.map +1 -1
- package/dist/components/Scope.js +38 -13
- package/dist/components/Scope.js.map +1 -1
- package/dist/components/awaitRestart.d.ts +33 -0
- package/dist/components/awaitRestart.js +61 -0
- package/dist/components/awaitRestart.js.map +1 -0
- package/dist/components/componentLoader.d.ts +38 -1
- package/dist/components/componentLoader.js +279 -22
- package/dist/components/componentLoader.js.map +1 -1
- package/dist/components/componentPreparationLock.d.ts +5 -0
- package/dist/components/componentPreparationLock.js +14 -6
- package/dist/components/componentPreparationLock.js.map +1 -1
- package/dist/components/mcp/adapters/harperHttp.js +4 -0
- package/dist/components/mcp/adapters/harperHttp.js.map +1 -1
- package/dist/components/mcp/listChanged.js +5 -0
- package/dist/components/mcp/listChanged.js.map +1 -1
- package/dist/components/mcp/toolRegistry.d.ts +1 -0
- package/dist/components/mcp/toolRegistry.js.map +1 -1
- package/dist/components/mcp/tools/operations.d.ts +5 -0
- package/dist/components/mcp/tools/operations.js +9 -0
- package/dist/components/mcp/tools/operations.js.map +1 -1
- package/dist/components/mcp/tools/schemas/operationDescriptions.js +2 -2
- package/dist/components/mcp/tools/schemas/operationDescriptions.js.map +1 -1
- package/dist/components/operations.js +231 -77
- package/dist/components/operations.js.map +1 -1
- package/dist/components/operationsValidation.js +49 -1
- package/dist/components/operationsValidation.js.map +1 -1
- package/dist/components/status/ComponentStatusRegistry.d.ts +0 -4
- package/dist/components/status/ComponentStatusRegistry.js +63 -0
- package/dist/components/status/ComponentStatusRegistry.js.map +1 -1
- package/dist/config/RootConfigWatcher.d.ts +7 -1
- package/dist/config/RootConfigWatcher.js +64 -27
- package/dist/config/RootConfigWatcher.js.map +1 -1
- package/dist/config/configUtils.d.ts +9 -1
- package/dist/config/configUtils.js +254 -33
- package/dist/config/configUtils.js.map +1 -1
- package/dist/config/harperConfigEnvVars.d.ts +16 -0
- package/dist/config/harperConfigEnvVars.js +162 -25
- package/dist/config/harperConfigEnvVars.js.map +1 -1
- package/dist/dataLayer/blobBackup.d.ts +49 -20
- package/dist/dataLayer/blobBackup.js +139 -50
- package/dist/dataLayer/blobBackup.js.map +1 -1
- package/dist/dataLayer/delete.js +1 -1
- package/dist/dataLayer/delete.js.map +1 -1
- package/dist/dataLayer/harperBridge/ResourceBridge.d.ts +14 -1
- package/dist/dataLayer/harperBridge/ResourceBridge.js +51 -10
- package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.d.ts +3 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +3 -1
- package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js.map +1 -1
- package/dist/dataLayer/hdbInfoController.d.ts +10 -0
- package/dist/dataLayer/hdbInfoController.js +30 -1
- package/dist/dataLayer/hdbInfoController.js.map +1 -1
- package/dist/dataLayer/insert.d.ts +9 -1
- package/dist/dataLayer/insert.js +30 -0
- package/dist/dataLayer/insert.js.map +1 -1
- package/dist/dataLayer/rocksdbBackup.d.ts +2 -2
- package/dist/dataLayer/rocksdbBackup.js +45 -8
- package/dist/dataLayer/rocksdbBackup.js.map +1 -1
- package/dist/dataLayer/schema.js +8 -0
- package/dist/dataLayer/schema.js.map +1 -1
- package/dist/dataLayer/schemaDescribe.js +8 -1
- package/dist/dataLayer/schemaDescribe.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/json/systemSchema.json +52 -0
- package/dist/resources/DatabaseTransaction.d.ts +55 -0
- package/dist/resources/DatabaseTransaction.js +459 -45
- package/dist/resources/DatabaseTransaction.js.map +1 -1
- package/dist/resources/LMDBTransaction.js +22 -4
- package/dist/resources/LMDBTransaction.js.map +1 -1
- package/dist/resources/PrimaryRocksDatabase.d.ts +1 -0
- package/dist/resources/PrimaryRocksDatabase.js +29 -0
- package/dist/resources/PrimaryRocksDatabase.js.map +1 -1
- package/dist/resources/RecordEncoder.d.ts +20 -0
- package/dist/resources/RecordEncoder.js +94 -9
- package/dist/resources/RecordEncoder.js.map +1 -1
- package/dist/resources/RequestTarget.d.ts +2 -0
- package/dist/resources/RequestTarget.js.map +1 -1
- package/dist/resources/Resource.js +20 -11
- package/dist/resources/Resource.js.map +1 -1
- package/dist/resources/ResourceInterface.d.ts +20 -1
- package/dist/resources/ResourceInterface.js.map +1 -1
- package/dist/resources/RocksIndexStore.d.ts +6 -1
- package/dist/resources/RocksIndexStore.js +24 -9
- package/dist/resources/RocksIndexStore.js.map +1 -1
- package/dist/resources/RocksTransactionLogStore.d.ts +14 -1
- package/dist/resources/RocksTransactionLogStore.js +57 -17
- package/dist/resources/RocksTransactionLogStore.js.map +1 -1
- package/dist/resources/Table.d.ts +112 -8
- package/dist/resources/Table.js +1073 -191
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/auditStore.d.ts +11 -2
- package/dist/resources/auditStore.js +325 -71
- package/dist/resources/auditStore.js.map +1 -1
- package/dist/resources/blob.d.ts +129 -9
- package/dist/resources/blob.js +992 -114
- package/dist/resources/blob.js.map +1 -1
- package/dist/resources/branchDatabase.d.ts +48 -0
- package/dist/resources/branchDatabase.js +892 -0
- package/dist/resources/branchDatabase.js.map +1 -0
- package/dist/resources/crdt.js +50 -12
- package/dist/resources/crdt.js.map +1 -1
- package/dist/resources/databases.d.ts +150 -0
- package/dist/resources/databases.js +1200 -239
- package/dist/resources/databases.js.map +1 -1
- package/dist/resources/defineTable.d.ts +10 -2
- package/dist/resources/defineTable.js +9 -1
- package/dist/resources/defineTable.js.map +1 -1
- package/dist/resources/graphql.d.ts +1 -1
- package/dist/resources/graphql.js +50 -15
- package/dist/resources/graphql.js.map +1 -1
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +1 -0
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +6 -2
- package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
- package/dist/resources/longLivedTransactions.d.ts +71 -0
- package/dist/resources/longLivedTransactions.js +358 -0
- package/dist/resources/longLivedTransactions.js.map +1 -0
- package/dist/resources/models/backendRegistry.d.ts +26 -0
- package/dist/resources/models/backendRegistry.js +60 -2
- package/dist/resources/models/backendRegistry.js.map +1 -1
- package/dist/resources/models/bootstrap.d.ts +33 -1
- package/dist/resources/models/bootstrap.js +416 -31
- package/dist/resources/models/bootstrap.js.map +1 -1
- package/dist/resources/recordLock.d.ts +80 -0
- package/dist/resources/recordLock.js +184 -0
- package/dist/resources/recordLock.js.map +1 -0
- package/dist/resources/replayLogs.d.ts +14 -1
- package/dist/resources/replayLogs.js +152 -24
- package/dist/resources/replayLogs.js.map +1 -1
- package/dist/resources/replayLogsGuards.d.ts +94 -7
- package/dist/resources/replayLogsGuards.js +111 -7
- package/dist/resources/replayLogsGuards.js.map +1 -1
- package/dist/resources/search.js +158 -6
- package/dist/resources/search.js.map +1 -1
- package/dist/resources/transactionBroadcast.d.ts +1 -1
- package/dist/resources/transactionBroadcast.js +2 -2
- package/dist/resources/transactionBroadcast.js.map +1 -1
- package/dist/security/auth.js +61 -30
- package/dist/security/auth.js.map +1 -1
- package/dist/security/authn/oidc/claims.d.ts +22 -0
- package/dist/security/authn/oidc/claims.js +71 -0
- package/dist/security/authn/oidc/claims.js.map +1 -0
- package/dist/security/authn/oidc/identityToken.d.ts +27 -0
- package/dist/security/authn/oidc/identityToken.js +111 -0
- package/dist/security/authn/oidc/identityToken.js.map +1 -0
- package/dist/security/authn/oidc/jwks.d.ts +25 -0
- package/dist/security/authn/oidc/jwks.js +261 -0
- package/dist/security/authn/oidc/jwks.js.map +1 -0
- package/dist/security/authn/oidc/providers/generic.d.ts +13 -0
- package/dist/security/authn/oidc/providers/generic.js +34 -0
- package/dist/security/authn/oidc/providers/generic.js.map +1 -0
- package/dist/security/authn/oidc/providers/githubActions.d.ts +11 -0
- package/dist/security/authn/oidc/providers/githubActions.js +129 -0
- package/dist/security/authn/oidc/providers/githubActions.js.map +1 -0
- package/dist/security/authn/oidc/providers/index.d.ts +37 -0
- package/dist/security/authn/oidc/providers/index.js +24 -0
- package/dist/security/authn/oidc/providers/index.js.map +1 -0
- package/dist/security/authn/oidc/tokenExchange.d.ts +12 -0
- package/dist/security/authn/oidc/tokenExchange.js +306 -0
- package/dist/security/authn/oidc/tokenExchange.js.map +1 -0
- package/dist/security/authn/oidc/trustPolicyOperations.d.ts +49 -0
- package/dist/security/authn/oidc/trustPolicyOperations.js +358 -0
- package/dist/security/authn/oidc/trustPolicyOperations.js.map +1 -0
- package/dist/security/authn/oidc/types.d.ts +38 -0
- package/dist/security/authn/oidc/types.js +6 -0
- package/dist/security/authn/oidc/types.js.map +1 -0
- package/dist/security/certificateVerification/index.js +40 -11
- package/dist/security/certificateVerification/index.js.map +1 -1
- package/dist/security/certificateVerification/trustedIssuers.d.ts +24 -0
- package/dist/security/certificateVerification/trustedIssuers.js +79 -0
- package/dist/security/certificateVerification/trustedIssuers.js.map +1 -0
- package/dist/security/certificateVerification/types.d.ts +1 -0
- package/dist/security/credentialProvenance.d.ts +35 -0
- package/dist/security/credentialProvenance.js +51 -0
- package/dist/security/credentialProvenance.js.map +1 -0
- package/dist/security/credentialRejection.d.ts +4 -0
- package/dist/security/credentialRejection.js +24 -0
- package/dist/security/credentialRejection.js.map +1 -0
- package/dist/security/deferredAuthentication.d.ts +36 -0
- package/dist/security/deferredAuthentication.js +70 -0
- package/dist/security/deferredAuthentication.js.map +1 -0
- package/dist/security/impersonation.d.ts +21 -0
- package/dist/security/impersonation.js +108 -9
- package/dist/security/impersonation.js.map +1 -1
- package/dist/security/jsLoader.d.ts +6 -0
- package/dist/security/jsLoader.js +75 -15
- package/dist/security/jsLoader.js.map +1 -1
- package/dist/security/keys.js +301 -71
- package/dist/security/keys.js.map +1 -1
- package/dist/security/operationScope.d.ts +21 -0
- package/dist/security/operationScope.js +36 -0
- package/dist/security/operationScope.js.map +1 -0
- package/dist/security/permissionsTranslator.js +21 -0
- package/dist/security/permissionsTranslator.js.map +1 -1
- package/dist/security/tokenAuthentication.d.ts +19 -1
- package/dist/security/tokenAuthentication.js +191 -10
- package/dist/security/tokenAuthentication.js.map +1 -1
- package/dist/security/user.js +4 -3
- package/dist/security/user.js.map +1 -1
- package/dist/server/DurableSubscriptionsSession.d.ts +2 -2
- package/dist/server/DurableSubscriptionsSession.js +67 -10
- package/dist/server/DurableSubscriptionsSession.js.map +1 -1
- package/dist/server/REST.js +73 -0
- package/dist/server/REST.js.map +1 -1
- package/dist/server/graphqlQuerying.js +4 -0
- package/dist/server/graphqlQuerying.js.map +1 -1
- package/dist/server/http.d.ts +11 -0
- package/dist/server/http.js +88 -15
- package/dist/server/http.js.map +1 -1
- package/dist/server/itc/serverHandlers.js +8 -1
- package/dist/server/itc/serverHandlers.js.map +1 -1
- package/dist/server/jobs/jobProcess.js +6 -2
- package/dist/server/jobs/jobProcess.js.map +1 -1
- package/dist/server/jobs/jobs.js +4 -1
- package/dist/server/jobs/jobs.js.map +1 -1
- package/dist/server/liveSubscriptionAuth.d.ts +26 -4
- package/dist/server/liveSubscriptionAuth.js +105 -39
- package/dist/server/liveSubscriptionAuth.js.map +1 -1
- package/dist/server/loadRootComponents.js +49 -10
- package/dist/server/loadRootComponents.js.map +1 -1
- package/dist/server/mqtt.d.ts +2 -0
- package/dist/server/mqtt.js +165 -30
- package/dist/server/mqtt.js.map +1 -1
- package/dist/server/nodeName.d.ts +2 -0
- package/dist/server/nodeName.js +107 -23
- package/dist/server/nodeName.js.map +1 -1
- package/dist/server/serverHelpers/Headers.d.ts +25 -0
- package/dist/server/serverHelpers/Headers.js +139 -1
- package/dist/server/serverHelpers/Headers.js.map +1 -1
- package/dist/server/serverHelpers/contentTypes.d.ts +9 -0
- package/dist/server/serverHelpers/contentTypes.js +32 -25
- package/dist/server/serverHelpers/contentTypes.js.map +1 -1
- package/dist/server/serverHelpers/deployValidationState.d.ts +3 -0
- package/dist/server/serverHelpers/deployValidationState.js +9 -19
- package/dist/server/serverHelpers/deployValidationState.js.map +1 -1
- package/dist/server/serverHelpers/operationAuthorizationState.d.ts +12 -0
- package/dist/server/serverHelpers/operationAuthorizationState.js +24 -2
- package/dist/server/serverHelpers/operationAuthorizationState.js.map +1 -1
- package/dist/server/serverHelpers/registeredOperations.d.ts +5 -4
- package/dist/server/serverHelpers/registeredOperations.js +74 -21
- package/dist/server/serverHelpers/registeredOperations.js.map +1 -1
- package/dist/server/serverHelpers/requestSanitization.d.ts +11 -0
- package/dist/server/serverHelpers/requestSanitization.js +20 -0
- package/dist/server/serverHelpers/requestSanitization.js.map +1 -0
- package/dist/server/serverHelpers/serverHandlers.js +6 -3
- package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
- package/dist/server/serverHelpers/serverUtilities.d.ts +18 -0
- package/dist/server/serverHelpers/serverUtilities.js +90 -20
- package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
- package/dist/server/serverHelpers/sharedMessageEncoding.d.ts +67 -0
- package/dist/server/serverHelpers/sharedMessageEncoding.js +280 -0
- package/dist/server/serverHelpers/sharedMessageEncoding.js.map +1 -0
- package/dist/server/serverHelpers/uwsServer.js +19 -1
- package/dist/server/serverHelpers/uwsServer.js.map +1 -1
- package/dist/server/static.js +24 -28
- package/dist/server/static.js.map +1 -1
- package/dist/server/storageReclamation.d.ts +12 -0
- package/dist/server/storageReclamation.js +26 -0
- package/dist/server/storageReclamation.js.map +1 -1
- package/dist/server/threads/itc.d.ts +7 -2
- package/dist/server/threads/itc.js +5 -1
- package/dist/server/threads/itc.js.map +1 -1
- package/dist/server/threads/manageThreads.d.ts +26 -3
- package/dist/server/threads/manageThreads.js +517 -65
- package/dist/server/threads/manageThreads.js.map +1 -1
- package/dist/server/threads/socketRouter.js +89 -26
- package/dist/server/threads/socketRouter.js.map +1 -1
- package/dist/server/threads/threadHeapMemory.d.ts +2 -0
- package/dist/server/threads/threadHeapMemory.js +31 -0
- package/dist/server/threads/threadHeapMemory.js.map +1 -0
- package/dist/server/threads/threadServer.js +46 -15
- package/dist/server/threads/threadServer.js.map +1 -1
- package/dist/sqlEngine/config.d.ts +1 -3
- package/dist/sqlEngine/config.js +19 -16
- package/dist/sqlEngine/config.js.map +1 -1
- package/dist/sqlTranslator/index.d.ts +1 -1
- package/dist/sqlTranslator/index.js +30 -7
- package/dist/sqlTranslator/index.js.map +1 -1
- package/dist/upgrade/directives/5-3-0.d.ts +7 -0
- package/dist/upgrade/directives/5-3-0.js +148 -0
- package/dist/upgrade/directives/5-3-0.js.map +1 -0
- package/dist/upgrade/directives/directivesController.js +2 -1
- package/dist/upgrade/directives/directivesController.js.map +1 -1
- package/dist/utility/OperationFunctionCaller.js +2 -1
- package/dist/utility/OperationFunctionCaller.js.map +1 -1
- package/dist/utility/common_utils.d.ts +16 -0
- package/dist/utility/common_utils.js +32 -6
- package/dist/utility/common_utils.js.map +1 -1
- package/dist/utility/componentNames.d.ts +8 -0
- package/dist/utility/componentNames.js +12 -1
- package/dist/utility/componentNames.js.map +1 -1
- package/dist/utility/environment/environmentManager.js +3 -6
- package/dist/utility/environment/environmentManager.js.map +1 -1
- package/dist/utility/environment/systemInformation.d.ts +1 -0
- package/dist/utility/environment/systemInformation.js +1 -0
- package/dist/utility/environment/systemInformation.js.map +1 -1
- package/dist/utility/errors/commonErrors.d.ts +2 -0
- package/dist/utility/errors/commonErrors.js +2 -0
- package/dist/utility/errors/commonErrors.js.map +1 -1
- package/dist/utility/errors/hdbError.d.ts +17 -0
- package/dist/utility/errors/hdbError.js +30 -1
- package/dist/utility/errors/hdbError.js.map +1 -1
- package/dist/utility/globalSchema.d.ts +18 -0
- package/dist/utility/hdbTerms.d.ts +16 -0
- package/dist/utility/hdbTerms.js +18 -2
- package/dist/utility/hdbTerms.js.map +1 -1
- package/dist/utility/logging/harper_logger.d.ts +2 -0
- package/dist/utility/logging/harper_logger.js +91 -14
- package/dist/utility/logging/harper_logger.js.map +1 -1
- package/dist/utility/logging/logRotator.js +76 -49
- package/dist/utility/logging/logRotator.js.map +1 -1
- package/dist/utility/nodeIdentity.d.ts +9 -0
- package/dist/utility/nodeIdentity.js +58 -0
- package/dist/utility/nodeIdentity.js.map +1 -0
- package/dist/utility/npmUtilities.js +9 -7
- package/dist/utility/npmUtilities.js.map +1 -1
- package/dist/utility/operationPermissions.d.ts +3 -1
- package/dist/utility/operationPermissions.js +16 -1
- package/dist/utility/operationPermissions.js.map +1 -1
- package/dist/utility/operation_authorization.d.ts +10 -7
- package/dist/utility/operation_authorization.js +212 -41
- package/dist/utility/operation_authorization.js.map +1 -1
- package/dist/utility/watchPath.d.ts +29 -0
- package/dist/utility/watchPath.js +68 -0
- package/dist/utility/watchPath.js.map +1 -0
- package/dist/utility/watcherFallback.d.ts +86 -0
- package/dist/utility/watcherFallback.js +278 -1
- package/dist/utility/watcherFallback.js.map +1 -1
- package/dist/validation/configValidator.d.ts +12 -0
- package/dist/validation/configValidator.js +199 -72
- package/dist/validation/configValidator.js.map +1 -1
- package/dist/validation/installValidator.js +12 -0
- package/dist/validation/installValidator.js.map +1 -1
- package/dist/validation/validationWrapper.d.ts +11 -0
- package/dist/validation/validationWrapper.js +16 -3
- package/dist/validation/validationWrapper.js.map +1 -1
- package/index.ts +2 -0
- package/json/systemSchema.json +52 -0
- package/npm-shrinkwrap.json +196 -194
- package/package.json +7 -6
- package/resources/DESIGN.md +114 -52
- package/resources/DatabaseTransaction.ts +521 -43
- package/resources/LMDBTransaction.ts +26 -4
- package/resources/PrimaryRocksDatabase.ts +28 -1
- package/resources/RecordEncoder.ts +103 -8
- package/resources/RequestTarget.ts +2 -0
- package/resources/Resource.ts +17 -9
- package/resources/ResourceInterface.ts +23 -0
- package/resources/RocksIndexStore.ts +30 -9
- package/resources/RocksTransactionLogStore.ts +78 -21
- package/resources/Table.ts +1110 -159
- package/resources/auditStore.ts +331 -73
- package/resources/blob.ts +1029 -110
- package/resources/branchDatabase.ts +941 -0
- package/resources/crdt.ts +76 -12
- package/resources/databases.ts +1310 -252
- package/resources/defineTable.ts +18 -2
- package/resources/graphql.ts +70 -16
- package/resources/indexes/HierarchicalNavigableSmallWorld.ts +6 -2
- package/resources/longLivedTransactions.ts +360 -0
- package/resources/models/backendRegistry.ts +84 -2
- package/resources/models/bootstrap.ts +473 -28
- package/resources/recordLock.ts +253 -0
- package/resources/replayLogs.ts +147 -26
- package/resources/replayLogsGuards.ts +171 -8
- package/resources/search.ts +154 -7
- package/resources/transactionBroadcast.ts +3 -3
- package/security/auth.ts +68 -29
- package/security/authn/oidc/claims.ts +72 -0
- package/security/authn/oidc/identityToken.ts +129 -0
- package/security/authn/oidc/jwks.ts +260 -0
- package/security/authn/oidc/providers/generic.ts +40 -0
- package/security/authn/oidc/providers/githubActions.ts +137 -0
- package/security/authn/oidc/providers/index.ts +52 -0
- package/security/authn/oidc/tokenExchange.ts +300 -0
- package/security/authn/oidc/trustPolicyOperations.ts +343 -0
- package/security/authn/oidc/types.ts +41 -0
- package/security/certificateVerification/index.ts +54 -13
- package/security/certificateVerification/trustedIssuers.ts +76 -0
- package/security/certificateVerification/types.ts +1 -0
- package/security/credentialProvenance.ts +47 -0
- package/security/credentialRejection.ts +22 -0
- package/security/deferredAuthentication.ts +71 -0
- package/security/impersonation.ts +117 -12
- package/security/jsLoader.ts +81 -18
- package/security/keys.ts +298 -72
- package/security/operationScope.ts +33 -0
- package/security/permissionsTranslator.js +23 -0
- package/security/tokenAuthentication.ts +233 -12
- package/security/user.ts +4 -3
- package/server/DESIGN.md +183 -16
- package/server/DurableSubscriptionsSession.ts +71 -11
- package/server/REST.ts +79 -1
- package/server/graphqlQuerying.ts +4 -0
- package/server/http.ts +99 -18
- package/server/itc/serverHandlers.js +8 -1
- package/server/jobs/jobProcess.ts +8 -2
- package/server/jobs/jobs.ts +4 -1
- package/server/liveSubscriptionAuth.ts +129 -46
- package/server/loadRootComponents.js +50 -8
- package/server/mqtt.ts +179 -38
- package/server/nodeName.ts +103 -21
- package/server/serverHelpers/Headers.ts +131 -0
- package/server/serverHelpers/contentTypes.ts +29 -21
- package/server/serverHelpers/deployValidationState.ts +24 -13
- package/server/serverHelpers/operationAuthorizationState.ts +34 -3
- package/server/serverHelpers/registeredOperations.ts +79 -22
- package/server/serverHelpers/requestSanitization.ts +15 -0
- package/server/serverHelpers/serverHandlers.js +6 -3
- package/server/serverHelpers/serverUtilities.ts +104 -31
- package/server/serverHelpers/sharedMessageEncoding.ts +307 -0
- package/server/serverHelpers/uwsServer.ts +17 -2
- package/server/static.ts +23 -29
- package/server/storageReclamation.ts +23 -0
- package/server/threads/itc.js +11 -1
- package/server/threads/manageThreads.js +526 -56
- package/server/threads/socketRouter.ts +81 -26
- package/server/threads/threadHeapMemory.ts +26 -0
- package/server/threads/threadServer.js +43 -15
- package/sqlTranslator/index.ts +31 -8
- package/studio/web/assets/Chat-BnCBegQz.js +2267 -0
- package/studio/web/assets/FloatingChat-CoDW1ySS.js +23 -0
- package/studio/web/assets/{abnfDiagram-VCTEODGH-C0_BAZyO.js → abnfDiagram-VCTEODGH-B0BebmD2.js} +1 -1
- package/studio/web/assets/{alertDialog-DIHt7Z0r.js → alertDialog-CQyAJJhl.js} +1 -1
- package/studio/web/assets/{apiToken-c3Rd-w6g.js → apiToken-Bwk5BLXW.js} +1 -1
- package/studio/web/assets/applications-DHxGi7JH.js +296 -0
- package/studio/web/assets/architecture-7GRP2DOG-LB-MLAAb.js +1 -0
- package/studio/web/assets/{architectureDiagram-5GKGNRK7-BWzrASgm.js → architectureDiagram-5GKGNRK7-7SW3GD-K.js} +1 -1
- package/studio/web/assets/authStore-C3Nfubqr.js +3 -0
- package/studio/web/assets/{blockDiagram-NRAW4CY4-BdJX9Khj.js → blockDiagram-I7D4REHJ-BqguiadH.js} +2 -2
- package/studio/web/assets/{button-DhiX-njv.js → button-BIsUKRZq.js} +2 -2
- package/studio/web/assets/{c4Diagram-UCG6FXSJ-CI6MzGmQ.js → c4Diagram-7LVT6UL2-LBNf8t_X.js} +1 -1
- package/studio/web/assets/channel-yictG-U-.js +1 -0
- package/studio/web/assets/{chevron-up-Df2c8uoU.js → chevron-up-DtKGqDn3.js} +1 -1
- package/studio/web/assets/{chunk-TEH6E4GO-P87k5mNi.js → chunk-4HAMMTFA-DWtTut21.js} +1 -1
- package/studio/web/assets/{chunk-75Z2AOVW-BT8tVmks.js → chunk-75Z2AOVW-QGQD6th2.js} +1 -1
- package/studio/web/assets/{chunk-DU6HZSFF-9kAOOmI6.js → chunk-DU6HZSFF-Chq20Ba5.js} +1 -1
- package/studio/web/assets/{chunk-F27PBJKO-BW7ao8AY.js → chunk-F27PBJKO-BVA5EPhV.js} +1 -1
- package/studio/web/assets/{chunk-GMAD6QVW-BNyXpoQO.js → chunk-GMAD6QVW-BeS7S07A.js} +1 -1
- package/studio/web/assets/{chunk-OBVCFTLP-D4wWOqDQ.js → chunk-GVQU2GXP-sbwVIQ8i.js} +1 -1
- package/studio/web/assets/{chunk-G27WJ6UU-COyLMcgK.js → chunk-IMKFNOWR-Bnh3tAVd.js} +1 -1
- package/studio/web/assets/{chunk-JQ64N6SF-Cyz1IeLf.js → chunk-L3NEJ4N5-COfUyKII.js} +1 -1
- package/studio/web/assets/chunk-OSK3NFVY-ByciRftO.js +10 -0
- package/studio/web/assets/{chunk-P2QGCYS3-DmIFY4d7.js → chunk-P2QGCYS3-CP1VhG_c.js} +1 -1
- package/studio/web/assets/{chunk-POPQ4Y6H-BPrvMyKz.js → chunk-POPQ4Y6H-ClWhhkwW.js} +1 -1
- package/studio/web/assets/{chunk-PWAF6VOD-2zB6IW9i.js → chunk-PWAF6VOD-1z1THyS5.js} +1 -1
- package/studio/web/assets/{chunk-RHFEMEQ7-2FgyI8YU.js → chunk-SHT3W25Y-LpQkMsah.js} +2 -2
- package/studio/web/assets/{chunk-SVP7TREG-FwtbH2QC.js → chunk-SVP7TREG-jtdAHw0S.js} +1 -1
- package/studio/web/assets/{chunk-LCL6LL3I-HOzK_ppE.js → chunk-TICWLB2K-VOwzetX-.js} +1 -1
- package/studio/web/assets/classDiagram-ZZMXUADV-VaEwSy_g.js +1 -0
- package/studio/web/assets/classDiagram-v2-VYDZK3BY-VaEwSy_g.js +1 -0
- package/studio/web/assets/{createLucideIcon-BKGPfjm2.js → createLucideIcon-CzW9508A.js} +1 -1
- package/studio/web/assets/{cssMode-CEN2mzSA.js → cssMode-s0cWI-_M.js} +1 -1
- package/studio/web/assets/{cynefin-OW5HDTMX-BRkpLFQV.js → cynefin-OW5HDTMX-BbdbCvub.js} +1 -1
- package/studio/web/assets/{cynefinDiagram-5FMLGOSQ-CHT1DaX6.js → cynefinDiagram-5FMLGOSQ-TP-aIqbt.js} +1 -1
- package/studio/web/assets/{dagre-3AP2YEHR-DpUXBh63.js → dagre-GXQ25YYZ-DShnGpGo.js} +1 -1
- package/studio/web/assets/{diagram-S7CK7UJ4-BuymVFZT.js → diagram-S7CK7UJ4-aoCVTtcy.js} +1 -1
- package/studio/web/assets/{diagram-UQ7AKVKN-CyP148RM.js → diagram-UQ7AKVKN-DglXtQ6x.js} +1 -1
- package/studio/web/assets/{diagram-VSXAHHWV-CoCAg3M9.js → diagram-VSXAHHWV-fhEdmkwM.js} +1 -1
- package/studio/web/assets/{diagram-VX7I27RA-BpOqCFca.js → diagram-VX7I27RA-DccVJet6.js} +1 -1
- package/studio/web/assets/{diagram-Z3DM3KII-Bfpw7Vbj.js → diagram-Z3DM3KII-D-RyJJb7.js} +1 -1
- package/studio/web/assets/{dialog-CBf0Mr1d.js → dialog-Cn2uWgD4.js} +1 -1
- package/studio/web/assets/{dist-lkA3O3eM.js → dist-DP8UjMB_.js} +1 -1
- package/studio/web/assets/{download-BtTOBem-.js → download-B5T5r7ss.js} +1 -1
- package/studio/web/assets/{ebnfDiagram-PWID7BFC-DS_6aWqL.js → ebnfDiagram-PWID7BFC-DJGpIpz_.js} +1 -1
- package/studio/web/assets/{editor-D8oDeCTL.js → editor-DNcRHK54.js} +1 -1
- package/studio/web/assets/{erDiagram-SSCWMZ5O-DJNk6Fgw.js → erDiagram-RLTQ6QDP-CIfNlgkC.js} +1 -1
- package/studio/web/assets/eventmodeling-NTZA5JFV-CLxnp2CR.js +1 -0
- package/studio/web/assets/flowDiagram-HODETNUW-BIbhmz9f.js +1 -0
- package/studio/web/assets/{ganttDiagram-EL5Y4UJY-2pOExxMY.js → ganttDiagram-EL5Y4UJY-BxToTzzD.js} +1 -1
- package/studio/web/assets/{getAnalytics-D4LKGeVy.js → getAnalytics-GHK8ORfM.js} +1 -1
- package/studio/web/assets/{gitGraph-4MIJSDKK-CH5ZxwzF.js → gitGraph-4MIJSDKK-D2s2w8lE.js} +1 -1
- package/studio/web/assets/{gitGraphDiagram-WWUBYQGX-DVIsIhbO.js → gitGraphDiagram-WWUBYQGX-Dwntd4-x.js} +1 -1
- package/studio/web/assets/{html-u3vOg7LJ.js → html-Bdssedlg.js} +1 -1
- package/studio/web/assets/{htmlMode-DyO31v-P.js → htmlMode-CoDlJ3fw.js} +1 -1
- package/studio/web/assets/{index-Cxj2_wsl.css → index-7RMEgVG1.css} +1 -1
- package/studio/web/assets/index-D6sxmFLR.js +824 -0
- package/studio/web/assets/index.lazy-tmU5BS8s.js +2 -0
- package/studio/web/assets/{info-A6RAGUB7-CPQfTnaG.js → info-A6RAGUB7-DYjkvb0C.js} +1 -1
- package/studio/web/assets/{infoDiagram-RXCK75RN-DlwLYlwm.js → infoDiagram-27XIBGKW-Bnp1FJE5.js} +1 -1
- package/studio/web/assets/{ishikawaDiagram-5VMMS53U-BRXRp29U.js → ishikawaDiagram-5VMMS53U-D9Xh2r6X.js} +1 -1
- package/studio/web/assets/{javascript-CUvxOyTC.js → javascript-B8meVSTH.js} +1 -1
- package/studio/web/assets/{journeyDiagram-EYS64GPL-B0ou8k0n.js → journeyDiagram-3NMN7TZE-CokIi6ll.js} +2 -2
- package/studio/web/assets/{jsonMode-f_IwbF3D.js → jsonMode-DpIPd35T.js} +1 -1
- package/studio/web/assets/{kanban-definition-3QL26DDD-uYg7iYzp.js → kanban-definition-UXKFOSKX-CukSFJfX.js} +1 -1
- package/studio/web/assets/{languageServices-DXtZ6rEF.js → languageServices-C_5FMJzQ.js} +1 -1
- package/studio/web/assets/{lspLanguageFeatures-B4pCF1zO.js → lspLanguageFeatures-BIzNBzPK.js} +1 -1
- package/studio/web/assets/{mermaid-parser.core-Ck-fC8b7.js → mermaid-parser.core-BlEsOWNO.js} +3 -3
- package/studio/web/assets/{mermaid.core-CP8aNNYm.js → mermaid.core-BlkGaMIH.js} +5 -5
- package/studio/web/assets/{mindmap-definition-FBJOCRG2-CgTZ-rit.js → mindmap-definition-YA3MSWOX-IprMc_0j.js} +1 -1
- package/studio/web/assets/{notifications-D3tIQ4sg.js → notifications-CQf18QKb.js} +1 -1
- package/studio/web/assets/notifications-CvZivSbh.js +1 -0
- package/studio/web/assets/{packet-AYTQ26CC-DEyoPtPb.js → packet-AYTQ26CC-Bi3V04Zi.js} +1 -1
- package/studio/web/assets/{pegDiagram-XKGWAZYB-DrD-7sD9.js → pegDiagram-XKGWAZYB-BNuPDLZY.js} +1 -1
- package/studio/web/assets/{pie-WAS4IAKB-wjj-EI1d.js → pie-WAS4IAKB-_6DoDbng.js} +1 -1
- package/studio/web/assets/{pieDiagram-E7YTZNPT-GntqDCzv.js → pieDiagram-E7YTZNPT-DqNb6Ht2.js} +1 -1
- package/studio/web/assets/{profile-DZWU7MgT.js → profile-DdOwtntb.js} +1 -1
- package/studio/web/assets/{quadrantDiagram-AXDQQJYC-0UeqXQGd.js → quadrantDiagram-AXDQQJYC-BGH9E2YR.js} +1 -1
- package/studio/web/assets/{radar-RG4KPBEZ-DFSA5h7k.js → radar-RG4KPBEZ-DDdVczcL.js} +1 -1
- package/studio/web/assets/{railroad-74A4TZTK-CaOUG9wR.js → railroad-74A4TZTK-BJUP4Jds.js} +1 -1
- package/studio/web/assets/railroad-abnf-HS5TGJTU-Bm3L1L0h.js +1 -0
- package/studio/web/assets/railroad-ebnf-LZEXJU2U-CKzLGlkw.js +1 -0
- package/studio/web/assets/railroad-peg-WCYAUIDC-S8xLjslx.js +1 -0
- package/studio/web/assets/{railroadDiagram-O6MQD6OU-yHUELZaV.js → railroadDiagram-O6MQD6OU-DGTPh2KZ.js} +1 -1
- package/studio/web/assets/{regions-CkyurXzE.js → regions-n69fwagr.js} +1 -1
- package/studio/web/assets/{register-BUyhWjBO.js → register-PfWTCXWB.js} +3 -3
- package/studio/web/assets/{requirementDiagram-EFPCY7ZU-DNEGFjuW.js → requirementDiagram-BXWQKSXE-BJnO6uLz.js} +1 -1
- package/studio/web/assets/{sankeyDiagram-P5KCCOFB-DpyAmSVR.js → sankeyDiagram-P5KCCOFB-0vSOdymH.js} +1 -1
- package/studio/web/assets/{sequenceDiagram-WJ2MYXX4-TyaT7xNk.js → sequenceDiagram-WJ2MYXX4-hETizDWE.js} +1 -1
- package/studio/web/assets/{setComponentFile-CeyKSZAa.js → setComponentFile-Bg6O7X0S.js} +1 -1
- package/studio/web/assets/{setup-D2kn7cAA.js → setup-CUx_aUDl.js} +2 -2
- package/studio/web/assets/{stateDiagram-HBIQ2CUA-CeEdTArZ.js → stateDiagram-D77RDMKH-CdYQ_KtC.js} +1 -1
- package/studio/web/assets/stateDiagram-v2-MP3YSRHH-CdKuzQMT.js +1 -0
- package/studio/web/assets/status-D7BVKqX9.js +61 -0
- package/studio/web/assets/{swimlanes-XN3QIQJK-B54FmF46.js → swimlanes-42K2YHIH-B8cHIpU4.js} +1 -1
- package/studio/web/assets/swimlanesDiagram-VR7AAH4N-DmOSJwaH.js +8 -0
- package/studio/web/assets/{tabs-B_G5zscN.js → tabs-BrHu7gJi.js} +1 -1
- package/studio/web/assets/{timeline-definition-24CTP7MA-D-a9ujbo.js → timeline-definition-24CTP7MA-BJWYSXqF.js} +1 -1
- package/studio/web/assets/{toggleHighContrast-C0UW6rI2.js → toggleHighContrast-DBSyXzMr.js} +1 -1
- package/studio/web/assets/{treeView-Q6P3EWNA-CrW_6JnS.js → treeView-Q6P3EWNA-qxe_v6CQ.js} +1 -1
- package/studio/web/assets/{treemap-WGGIJYW6-BxyYLdP_.js → treemap-WGGIJYW6-dDo97XXF.js} +1 -1
- package/studio/web/assets/{tsMode-DBC0zmDx.js → tsMode-BByKCjBS.js} +1 -1
- package/studio/web/assets/{typescript-DApRQir3.js → typescript-DDLnLpw9.js} +1 -1
- package/studio/web/assets/{useEntityRestURL-DB6JStU1.js → useEntityRestURL-31CHGaHk.js} +1 -1
- package/studio/web/assets/{useLocalStorage-Dtj1QS8_.js → useLocalStorage-BqMR3D8_.js} +1 -1
- package/studio/web/assets/vendor-core-c2JRRJpV.js +58 -0
- package/studio/web/assets/vendor-datadog-CLUcJXOo.js +6 -0
- package/studio/web/assets/{vendor-react-Dyj4O3HE.js → vendor-react-CJV_K1u4.js} +1 -1
- package/studio/web/assets/vendor-tanstack-DxzraizX.js +1 -0
- package/studio/web/assets/{vendor-ui-vhu-UHhF.js → vendor-ui-BUjK0h8a.js} +2 -2
- package/studio/web/assets/{vennDiagram-4TSXK5OY-Cy7s7Mpy.js → vennDiagram-4TSXK5OY-A3i-lCdl.js} +1 -1
- package/studio/web/assets/{wardley-WFR3VGLG-BeBL35g2.js → wardley-WFR3VGLG-B0ik-_6g.js} +1 -1
- package/studio/web/assets/{wardleyDiagram-VM6X3IG4-BylmIGSg.js → wardleyDiagram-VM6X3IG4-CjrkKWUR.js} +1 -1
- package/studio/web/assets/{workers-C0bFIedw.js → workers-pR3jRY9D.js} +1 -1
- package/studio/web/assets/x-DIzaLEdK.js +1 -0
- package/studio/web/assets/{xml-HWd01lU-.js → xml-2iRnMhQO.js} +1 -1
- package/studio/web/assets/{xychartDiagram-S5SC5T6Z-CoKALMXr.js → xychartDiagram-S5SC5T6Z-Biok4GYV.js} +1 -1
- package/studio/web/assets/{yaml-CIH0Nt-h.js → yaml-Bf92gJpd.js} +1 -1
- package/studio/web/index.html +14 -14
- package/upgrade/directives/5-3-0.ts +132 -0
- package/upgrade/directives/directivesController.ts +2 -1
- package/utility/OperationFunctionCaller.ts +2 -1
- package/utility/common_utils.ts +30 -5
- package/utility/componentNames.ts +12 -0
- package/utility/environment/environmentManager.ts +3 -7
- package/utility/environment/systemInformation.ts +7 -0
- package/utility/errors/commonErrors.ts +4 -0
- package/utility/errors/hdbError.ts +29 -0
- package/utility/hdbTerms.ts +17 -0
- package/utility/logging/harper_logger.ts +87 -14
- package/utility/logging/logRotator.ts +72 -45
- package/utility/nodeIdentity.ts +45 -0
- package/utility/npmUtilities.ts +10 -8
- package/utility/operationPermissions.ts +18 -1
- package/utility/operation_authorization.ts +231 -42
- package/utility/watchPath.ts +63 -0
- package/utility/watcherFallback.ts +270 -0
- package/validation/configValidator.ts +209 -72
- package/validation/installValidator.ts +15 -0
- package/validation/validationWrapper.ts +18 -4
- package/studio/web/assets/Chat-JpO8EtUu.js +0 -2067
- package/studio/web/assets/FloatingChat-Bcj3xSZu.js +0 -23
- package/studio/web/assets/applications-ByqLRKyZ.js +0 -296
- package/studio/web/assets/architecture-7GRP2DOG-DNdx5tEU.js +0 -1
- package/studio/web/assets/authStore-qKmCZcaf.js +0 -3
- package/studio/web/assets/channel-DtCV8PTL.js +0 -1
- package/studio/web/assets/chunk-R7TYR2AO-Irip67yr.js +0 -10
- package/studio/web/assets/classDiagram-DTDB5LWJ-DbO_dCNE.js +0 -1
- package/studio/web/assets/classDiagram-v2-JRS7N3AN-DbO_dCNE.js +0 -1
- package/studio/web/assets/eventmodeling-NTZA5JFV-5jbe4A5P.js +0 -1
- package/studio/web/assets/flowDiagram-A5DVABFB-Dp9Ezlow.js +0 -1
- package/studio/web/assets/index-aSt5tY-L.js +0 -824
- package/studio/web/assets/index.lazy-B9jiPwT8.js +0 -2
- package/studio/web/assets/notifications-CUoYgU98.js +0 -1
- package/studio/web/assets/railroad-abnf-HS5TGJTU-Bc0Qi0WH.js +0 -1
- package/studio/web/assets/railroad-ebnf-LZEXJU2U-G8rVVZ2C.js +0 -1
- package/studio/web/assets/railroad-peg-WCYAUIDC-CrehKBhC.js +0 -1
- package/studio/web/assets/stateDiagram-v2-4QOOHH4V-D4tuw9Su.js +0 -1
- package/studio/web/assets/status-D7Xn5ePA.js +0 -61
- package/studio/web/assets/swimlanesDiagram-VK2B7HYN-XOhmNEvq.js +0 -8
- package/studio/web/assets/vendor-core-RCcadM3e.js +0 -73
- package/studio/web/assets/vendor-datadog-BRv-mOv1.js +0 -6
- package/studio/web/assets/vendor-tanstack-BiFWSB3W.js +0 -1
- package/studio/web/assets/x-B9o9hsep.js +0 -1
- /package/studio/web/assets/{sizeCapture-X5ZJPWSS-B0uUizjq.js → sizeCapture-INFHLROL-B0uUizjq.js} +0 -0
|
@@ -36,16 +36,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Application = exports.GIT_CREDENTIAL_HELPER_PATH = exports.ASIDE_STAGING_DIR = exports.InvalidCredentialEntryError = exports.InvalidCredentialsPropertyError = exports.InvalidInstallTimeoutError = exports.InvalidInstallCommandError = exports.InvalidInstallPropertyError = exports.InvalidPackageIdentifierError = void 0;
|
|
39
|
+
exports.Application = exports.GIT_CREDENTIAL_HELPER_PATH = exports.DEPLOY_STAGING_DIR = exports.ASIDE_STAGING_DIR = exports.InvalidCredentialEntryError = exports.InvalidBranchedDatabasesError = exports.InvalidCredentialsPropertyError = exports.InvalidInstallTimeoutError = exports.InvalidInstallCommandError = exports.InvalidInstallPropertyError = exports.InvalidPackageIdentifierError = void 0;
|
|
40
40
|
exports.assertApplicationConfig = assertApplicationConfig;
|
|
41
|
+
exports.assertBranchedDatabases = assertBranchedDatabases;
|
|
41
42
|
exports.isSSHAuthFailure = isSSHAuthFailure;
|
|
42
43
|
exports.parseGitReference = parseGitReference;
|
|
44
|
+
exports.packageHasProductionInstallWork = packageHasProductionInstallWork;
|
|
45
|
+
exports.packageHasAutomaticInstallWork = packageHasAutomaticInstallWork;
|
|
43
46
|
exports.readInstalledPackageMetadata = readInstalledPackageMetadata;
|
|
44
47
|
exports.installedPackageMetadataEqual = installedPackageMetadataEqual;
|
|
45
48
|
exports.installedRuntimeChanged = installedRuntimeChanged;
|
|
46
49
|
exports.extractApplication = extractApplication;
|
|
50
|
+
exports.candidateApplicationPath = candidateApplicationPath;
|
|
51
|
+
exports.makeRollbackPlaceholderMovable = makeRollbackPlaceholderMovable;
|
|
52
|
+
exports.splitAttributionOwners = splitAttributionOwners;
|
|
53
|
+
exports.unsettleableComponentsFromDisk = unsettleableComponentsFromDisk;
|
|
54
|
+
exports.recoverInterruptedActivations = recoverInterruptedActivations;
|
|
55
|
+
exports.markCandidateComplete = markCandidateComplete;
|
|
56
|
+
exports.activateCandidateApplication = activateCandidateApplication;
|
|
57
|
+
exports.buildCandidateApplication = buildCandidateApplication;
|
|
58
|
+
exports.recoverInterruptedComponentExtractions = recoverInterruptedComponentExtractions;
|
|
59
|
+
exports.recoverInterruptedComponentExtraction = recoverInterruptedComponentExtraction;
|
|
60
|
+
exports.retireComponentExtractionStaging = retireComponentExtractionStaging;
|
|
61
|
+
exports.dropComponentDirectory = dropComponentDirectory;
|
|
62
|
+
exports.packageManagerInstallArguments = packageManagerInstallArguments;
|
|
47
63
|
exports.installApplication = installApplication;
|
|
48
64
|
exports.derivePackageIdentifier = derivePackageIdentifier;
|
|
65
|
+
exports.shouldPackLocalDirectory = shouldPackLocalDirectory;
|
|
49
66
|
exports.prepareApplication = prepareApplication;
|
|
50
67
|
exports.installApplications = installApplications;
|
|
51
68
|
exports.recordApplicationPreparation = recordApplicationPreparation;
|
|
@@ -109,6 +126,12 @@ class InvalidCredentialsPropertyError extends TypeError {
|
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
128
|
exports.InvalidCredentialsPropertyError = InvalidCredentialsPropertyError;
|
|
129
|
+
class InvalidBranchedDatabasesError extends TypeError {
|
|
130
|
+
constructor(applicationName, detail) {
|
|
131
|
+
super(`Invalid 'branchedDatabases' for application ${applicationName}: ${detail}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.InvalidBranchedDatabasesError = InvalidBranchedDatabasesError;
|
|
112
135
|
class InvalidCredentialEntryError extends TypeError {
|
|
113
136
|
constructor(applicationName) {
|
|
114
137
|
super(`Invalid 'credentials' entry for application ${applicationName}: expected a { registry, secret, scope? } ` +
|
|
@@ -117,6 +140,15 @@ class InvalidCredentialEntryError extends TypeError {
|
|
|
117
140
|
}
|
|
118
141
|
exports.InvalidCredentialEntryError = InvalidCredentialEntryError;
|
|
119
142
|
function assertApplicationConfig(applicationName, applicationConfig) {
|
|
143
|
+
// The deploy staging directory holds a candidate tree under the component's own name beside dot-prefixed
|
|
144
|
+
// control files, so a dot-prefixed component name collides with one of them — and an application named
|
|
145
|
+
// `.activation.json` puts its tree on the journal path, where the journal write takes EEXIST as "a retry
|
|
146
|
+
// of this activation" and the swap proceeds with no journal at all. Rejected HERE rather than tolerated
|
|
147
|
+
// downstream: nothing else validates a root-config application key.
|
|
148
|
+
if (!isJoinableComponentName(applicationName)) {
|
|
149
|
+
throw new Error(`Invalid application name '${applicationName}': it must be a single path segment and must not begin ` +
|
|
150
|
+
`with a dot, which is reserved for Harper's own deploy control files`);
|
|
151
|
+
}
|
|
120
152
|
if (typeof applicationConfig.package !== 'string') {
|
|
121
153
|
throw new InvalidPackageIdentifierError(applicationName, applicationConfig.package);
|
|
122
154
|
}
|
|
@@ -162,6 +194,38 @@ function assertApplicationConfig(applicationName, applicationConfig) {
|
|
|
162
194
|
}
|
|
163
195
|
}
|
|
164
196
|
}
|
|
197
|
+
assertBranchedDatabases(applicationName, applicationConfig.branchedDatabases);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A branch that cannot be honoured fails the application's load: falling back would hand it the
|
|
201
|
+
* shared database it asked not to have, with no signal that it happened.
|
|
202
|
+
*/
|
|
203
|
+
function assertBranchedDatabases(applicationName, value) {
|
|
204
|
+
if (value === undefined || value === true)
|
|
205
|
+
return;
|
|
206
|
+
if (!Array.isArray(value)) {
|
|
207
|
+
throw new InvalidBranchedDatabasesError(applicationName, `expected an array or true, got ${typeof value}`);
|
|
208
|
+
}
|
|
209
|
+
const seen = new Set();
|
|
210
|
+
for (const name of value) {
|
|
211
|
+
if (typeof name !== 'string' || name === '') {
|
|
212
|
+
throw new InvalidBranchedDatabasesError(applicationName, `expected database names, got ${typeof name}`);
|
|
213
|
+
}
|
|
214
|
+
// A branch is a directory named by this value; a separator or traversal segment would escape
|
|
215
|
+
// the reserved branch root.
|
|
216
|
+
if (name.includes('/') || name.includes('\\') || name === '.' || name === '..') {
|
|
217
|
+
throw new InvalidBranchedDatabasesError(applicationName, `'${name}' is not a usable database name`);
|
|
218
|
+
}
|
|
219
|
+
// `system` carries the instance's own catalog, users and jobs; a private fork of it would give
|
|
220
|
+
// the application a divergent view of the instance rather than of its data.
|
|
221
|
+
if (name === 'system') {
|
|
222
|
+
throw new InvalidBranchedDatabasesError(applicationName, `the 'system' database cannot be branched`);
|
|
223
|
+
}
|
|
224
|
+
if (seen.has(name)) {
|
|
225
|
+
throw new InvalidBranchedDatabasesError(applicationName, `'${name}' is listed more than once`);
|
|
226
|
+
}
|
|
227
|
+
seen.add(name);
|
|
228
|
+
}
|
|
165
229
|
}
|
|
166
230
|
/**
|
|
167
231
|
* Returns true when npm/git stderr indicates an SSH authentication failure —
|
|
@@ -406,10 +470,42 @@ async function runNpmPack(application, packArgs, cwd, gitCredentialEnv) {
|
|
|
406
470
|
// during a deploy swap (see extractApplication). The leading dot keeps
|
|
407
471
|
// loadComponentDirectories from loading its contents as components.
|
|
408
472
|
exports.ASIDE_STAGING_DIR = '.deploy-aside';
|
|
473
|
+
// Hidden directory under the components root holding per-deployment candidate builds. A candidate is
|
|
474
|
+
// extracted, installed AND validated here, and only then renamed into the live path, so the previous
|
|
475
|
+
// version keeps serving through the slow, failure-prone work. Dot-prefixed so the three scans over the
|
|
476
|
+
// components root (componentLoader, componentEnvPrepass, resolvePreload) skip it.
|
|
477
|
+
exports.DEPLOY_STAGING_DIR = '.deploy-staging';
|
|
478
|
+
const IN_PROGRESS_ASIDE_PREFIX = '.in-progress-';
|
|
479
|
+
const RETIRED_ASIDE_PREFIX = '.retired-';
|
|
480
|
+
const PRIOR_ABSENT_RECORD_SUFFIX = '-prior-absent';
|
|
409
481
|
const DEFAULT_COMMAND_TIMEOUT_MS = 60 * 60 * 1000;
|
|
410
482
|
const COMPONENT_PREPARATION_WAIT_MARGIN_MS = 30000;
|
|
483
|
+
const COMPONENT_RECOVERY_WAIT_TIMEOUT_MS = 30000;
|
|
484
|
+
const COMPONENT_RECOVERY_TRY_TIMEOUT_MS = 250;
|
|
485
|
+
/**
|
|
486
|
+
* Lock terms for the boot-time activation scan. It runs before every component load on every thread, so it
|
|
487
|
+
* probes rather than queues: the default is a two-hour wait that RENEWS while the holder is alive, which
|
|
488
|
+
* would park a respawning worker behind a deploy's `npm install` and load no components at all until it
|
|
489
|
+
* finished. A held lock means a live deploy, and a live deploy settles its own journal.
|
|
490
|
+
*/
|
|
491
|
+
const RECOVERY_LOCK_WAIT = {
|
|
492
|
+
timeoutMs: COMPONENT_RECOVERY_TRY_TIMEOUT_MS,
|
|
493
|
+
renewTimeoutWhileOwnerAlive: false,
|
|
494
|
+
};
|
|
495
|
+
const COMPONENT_RECOVERY_LOCK_PURPOSE = 'component-recovery';
|
|
411
496
|
const MAX_GIT_EXTRACTION_COMMANDS = 4;
|
|
412
497
|
const MAX_INSTALL_COMMANDS = 2;
|
|
498
|
+
const PRODUCTION_DEPENDENCY_FIELDS = ['dependencies', 'optionalDependencies', 'peerDependencies'];
|
|
499
|
+
const INSTALL_LIFECYCLE_SCRIPTS = new Set([
|
|
500
|
+
'preinstall',
|
|
501
|
+
'install',
|
|
502
|
+
'postinstall',
|
|
503
|
+
'prepublish',
|
|
504
|
+
'preprepare',
|
|
505
|
+
'prepare',
|
|
506
|
+
'postprepare',
|
|
507
|
+
'dependencies',
|
|
508
|
+
]);
|
|
413
509
|
// The credential helper git executes for a private git-reference deploy. It ships alongside this
|
|
414
510
|
// module (both in source and in dist), holds no secret, and is inert without a live session.
|
|
415
511
|
exports.GIT_CREDENTIAL_HELPER_PATH = (0, node_path_1.join)(__dirname, 'gitCredentialHelper.js');
|
|
@@ -421,6 +517,47 @@ const PACKAGE_LOCK_FILES = [
|
|
|
421
517
|
'bun.lock',
|
|
422
518
|
'bun.lockb',
|
|
423
519
|
];
|
|
520
|
+
function dependencyFieldHasWork(packageJSON, field) {
|
|
521
|
+
if (!packageJSON || typeof packageJSON !== 'object' || !Object.hasOwn(packageJSON, field))
|
|
522
|
+
return false;
|
|
523
|
+
const value = packageJSON[field];
|
|
524
|
+
return !value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length > 0;
|
|
525
|
+
}
|
|
526
|
+
function packageHasProductionInstallWork(packageJSON) {
|
|
527
|
+
if (packageJSON === undefined)
|
|
528
|
+
return false;
|
|
529
|
+
if (!packageJSON || typeof packageJSON !== 'object' || Array.isArray(packageJSON))
|
|
530
|
+
return true;
|
|
531
|
+
if (PRODUCTION_DEPENDENCY_FIELDS.some((field) => dependencyFieldHasWork(packageJSON, field)))
|
|
532
|
+
return true;
|
|
533
|
+
if (!Object.hasOwn(packageJSON, 'workspaces'))
|
|
534
|
+
return false;
|
|
535
|
+
const workspaces = packageJSON.workspaces;
|
|
536
|
+
if (Array.isArray(workspaces))
|
|
537
|
+
return workspaces.length > 0;
|
|
538
|
+
if (!workspaces || typeof workspaces !== 'object' || !Object.hasOwn(workspaces, 'packages'))
|
|
539
|
+
return true;
|
|
540
|
+
return !Array.isArray(workspaces.packages) || workspaces.packages.length > 0;
|
|
541
|
+
}
|
|
542
|
+
function packageHasExplicitNonNpmManager(packageJSON) {
|
|
543
|
+
const packageManager = packageJSON?.devEngines?.packageManager;
|
|
544
|
+
return !!packageManager && packageManager.name !== 'npm';
|
|
545
|
+
}
|
|
546
|
+
function packageHasAutomaticInstallWork(packageJSON) {
|
|
547
|
+
return packageHasProductionInstallWork(packageJSON) || packageHasExplicitNonNpmManager(packageJSON);
|
|
548
|
+
}
|
|
549
|
+
function packageHasAllowedInstallLifecycleWork(packageJSON) {
|
|
550
|
+
if (!packageJSON || typeof packageJSON !== 'object' || !Object.hasOwn(packageJSON, 'scripts'))
|
|
551
|
+
return false;
|
|
552
|
+
const scripts = packageJSON.scripts;
|
|
553
|
+
if (!scripts || typeof scripts !== 'object' || Array.isArray(scripts))
|
|
554
|
+
return true;
|
|
555
|
+
return [...INSTALL_LIFECYCLE_SCRIPTS].some((name) => {
|
|
556
|
+
if (!Object.hasOwn(scripts, name))
|
|
557
|
+
return false;
|
|
558
|
+
return typeof scripts[name] !== 'string' || scripts[name].trim().length > 0;
|
|
559
|
+
});
|
|
560
|
+
}
|
|
424
561
|
async function readInstalledPackageMetadata(directory) {
|
|
425
562
|
const files = new Map();
|
|
426
563
|
let readable = true;
|
|
@@ -456,13 +593,7 @@ async function readInstalledPackageMetadata(directory) {
|
|
|
456
593
|
files,
|
|
457
594
|
readable,
|
|
458
595
|
hasLockfile: PACKAGE_LOCK_FILES.some((filename) => files.has(filename)),
|
|
459
|
-
hasInstallableDependencies:
|
|
460
|
-
const dependencies = packageJSON?.[field];
|
|
461
|
-
return (typeof dependencies === 'object' &&
|
|
462
|
-
dependencies !== null &&
|
|
463
|
-
!Array.isArray(dependencies) &&
|
|
464
|
-
Object.keys(dependencies).length > 0);
|
|
465
|
-
}),
|
|
596
|
+
hasInstallableDependencies: packageHasAutomaticInstallWork(packageJSON),
|
|
466
597
|
};
|
|
467
598
|
}
|
|
468
599
|
function installedPackageMetadataEqual(previous, current) {
|
|
@@ -489,26 +620,8 @@ function canonicalizeJSON(value) {
|
|
|
489
620
|
canonical[key] = canonicalizeJSON(value[key]);
|
|
490
621
|
return canonical;
|
|
491
622
|
}
|
|
492
|
-
/**
|
|
493
|
-
|
|
494
|
-
*
|
|
495
|
-
* Only one of `application.payload` or `application.package` should be specified; otherwise, an error is thrown.
|
|
496
|
-
*
|
|
497
|
-
* Writes the application to the configured components root directory using the `application.name` and overwrites any existing directory.
|
|
498
|
-
*
|
|
499
|
-
* This method may be called from any Harper thread. Same-component calls are serialized across
|
|
500
|
-
* threads by the preparation lock below.
|
|
501
|
-
*/
|
|
502
|
-
async function extractApplication(application, deferCommit = false) {
|
|
503
|
-
// Can't specify neither
|
|
504
|
-
if (!application.payload && !application.packageIdentifier) {
|
|
505
|
-
throw new Error('Either payload or package must be provided');
|
|
506
|
-
}
|
|
507
|
-
// Can't specify both
|
|
508
|
-
if (application.payload && application.packageIdentifier) {
|
|
509
|
-
throw new Error('Both payload and package cannot be provided');
|
|
510
|
-
}
|
|
511
|
-
// Resolve the tarball from the input
|
|
623
|
+
/** Resolve `payload` or `package` into a tarball stream. Touches neither the live tree nor staging. */
|
|
624
|
+
async function resolveApplicationTarball(application) {
|
|
512
625
|
let tarballPath;
|
|
513
626
|
let tarball;
|
|
514
627
|
let shouldDeleteTarball = false;
|
|
@@ -530,6 +643,8 @@ async function extractApplication(application, deferCommit = false) {
|
|
|
530
643
|
else {
|
|
531
644
|
// Given a package, there are a a couple options
|
|
532
645
|
const parentDirPath = (0, node_path_1.dirname)(application.dirPath);
|
|
646
|
+
let packageIdentifierForPack = application.packageIdentifier;
|
|
647
|
+
let packageNeedsPacking = true;
|
|
533
648
|
// If the package identifier is a file path we need to check if its a tarball or a directory
|
|
534
649
|
if (application.packageIdentifier.startsWith('file:')) {
|
|
535
650
|
const packagePath = application.packageIdentifier.slice(5);
|
|
@@ -537,235 +652,2026 @@ async function extractApplication(application, deferCommit = false) {
|
|
|
537
652
|
// Have to remove the 'file:' prefix in order to use fs methods
|
|
538
653
|
const stats = await (0, promises_1.stat)(packagePath);
|
|
539
654
|
if (stats.isDirectory()) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
655
|
+
if (!application.packLocalDirectory) {
|
|
656
|
+
// Reported, not performed — the caller decides where the link goes, so a candidate build
|
|
657
|
+
// links at the candidate path rather than onto the live one.
|
|
658
|
+
return { kind: 'link', sourceDirPath: packagePath };
|
|
659
|
+
}
|
|
660
|
+
// Bare absolute Windows directory inputs historically materialize a copy through npm pack;
|
|
661
|
+
// explicit file: and relative directories remain live links.
|
|
662
|
+
packageIdentifierForPack = packagePath;
|
|
663
|
+
application.logger.debug?.('Packaging local component directory instead of linking it on Windows');
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
if (!stats.isFile()) {
|
|
667
|
+
throw new Error(`File path specified in package identifier is not a file or directory: ${packagePath}`);
|
|
668
|
+
}
|
|
669
|
+
// If its a file, we assume it can be unzipped and extracted.
|
|
670
|
+
// We are using maybe-gunzip to handle both gzipped and non-gzipped tarballs
|
|
671
|
+
// And then we are happy to let the `tar-fs` library handle the extraction.
|
|
672
|
+
// Maybe worth adding some detection or at least some error handling if that step below fails.
|
|
673
|
+
tarballPath = packagePath;
|
|
674
|
+
tarball = (0, node_fs_1.createReadStream)(tarballPath);
|
|
675
|
+
packageNeedsPacking = false;
|
|
676
|
+
application.logger.debug?.('Using local component archive directly without npm pack');
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
catch (err) {
|
|
680
|
+
if (err.code === 'ENOENT') {
|
|
681
|
+
throw new Error(`File path specified in package identifier does not exist: ${packagePath}`);
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
throw err;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (packageNeedsPacking) {
|
|
689
|
+
// `npm pack --json` writes a JSON array describing the packed tarball(s). This is also the
|
|
690
|
+
// spawn that clones a git-reference package, so it is the only one given the git credential
|
|
691
|
+
// environment.
|
|
692
|
+
//
|
|
693
|
+
// Packing a git reference is not just a download: npm clones the repo and, if its manifest
|
|
694
|
+
// has a prepare/build/install script, runs `npm install` inside the clone and then that
|
|
695
|
+
// script — so the repository's (and its dependencies') install scripts can execute on this
|
|
696
|
+
// node during the pack step alone, independent of the later `npm install`.
|
|
697
|
+
// `install_allow_scripts` is the operator-facing switch for whether component code is
|
|
698
|
+
// allowed to run scripts on this node at all — with a credential session live, an
|
|
699
|
+
// unreviewed script also reaching the socket (a transitive dependency's postinstall asking
|
|
700
|
+
// for a token granted to the top-level repository) is exactly the reach the credential must
|
|
701
|
+
// not have, so this gates the pack step regardless of whether a credential happens to be in
|
|
702
|
+
// play.
|
|
703
|
+
const allowScripts = !!application.install?.allowInstallScripts;
|
|
704
|
+
if (allowScripts)
|
|
705
|
+
application.installationIsOpaque = true;
|
|
706
|
+
// `--ignore-scripts` alone isn't a reliable way to enforce that: pacote's DirFetcher runs a
|
|
707
|
+
// git source's `prepare` unconditionally on npm versions before 11.0.0 (see
|
|
708
|
+
// packGitReferenceWithoutScripts), which is exactly what Node 22's bundled npm ships. For a
|
|
709
|
+
// recognized git-reference identifier, clone and pack it ourselves with scripts stripped
|
|
710
|
+
// instead, sidestepping that npm code path entirely.
|
|
711
|
+
const gitRef = allowScripts ? null : parseGitReference(packageIdentifierForPack);
|
|
712
|
+
if (!allowScripts && !gitRef && looksLikeGitReference(packageIdentifierForPack)) {
|
|
713
|
+
// Recognized as git, but a form the reclone-and-strip-scripts path above can't safely
|
|
714
|
+
// handle (a `#path:` committish, or a hosted shorthand other than a plain `owner/repo`) —
|
|
715
|
+
// fail loudly rather than silently falling through to the unreliable `npm pack
|
|
716
|
+
// --ignore-scripts` below.
|
|
717
|
+
throw new Error(`Cannot deploy git-reference package '${packageIdentifierForPack}' with install scripts disallowed: this identifier's form (e.g. a '#path:' committish, or a hosted shorthand other than a plain 'owner/repo') isn't one this repo's script-suppression handling supports. Set install.allowInstallScripts to true, or use a plain git URL with a branch/tag/commit committish instead.`);
|
|
718
|
+
}
|
|
719
|
+
if (gitRef) {
|
|
720
|
+
tarballPath = await packGitReferenceWithoutScripts(application, gitRef, parentDirPath);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
const packArgs = ['pack', '--json', packageIdentifierForPack];
|
|
724
|
+
if (!allowScripts) {
|
|
725
|
+
packArgs.push('--ignore-scripts');
|
|
726
|
+
}
|
|
727
|
+
else if (application.gitCredentialEnv) {
|
|
728
|
+
application.logger.warn(`Deploying ${application.name} from a git reference with install scripts enabled: the repository's ` +
|
|
729
|
+
`prepare/build scripts and its dependencies' install scripts run on this node during the clone and ` +
|
|
730
|
+
`can read the git credential. Unset install_allow_scripts to keep the credential out of their reach.`);
|
|
731
|
+
}
|
|
732
|
+
tarballPath = await runNpmPack(application, packArgs, parentDirPath, application.gitCredentialEnv);
|
|
733
|
+
}
|
|
734
|
+
shouldDeleteTarball = true;
|
|
735
|
+
tarball = (0, node_fs_1.createReadStream)(tarballPath);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return { kind: 'tarball', tarball, tarballPath, shouldDeleteTarball };
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Extract a tarball into `targetDirPath`, flattening the single wrapping directory npm pack produces.
|
|
742
|
+
* `scratchDirPath` must be on the same filesystem as the target: the flatten is done by renaming the
|
|
743
|
+
* wrapper out and back rather than copying, so it stays atomic per entry. Windows moves the children
|
|
744
|
+
* individually because renaming a directory over its own parent's path fails there.
|
|
745
|
+
*/
|
|
746
|
+
async function extractTarballInto(tarball, targetDirPath, scratchDirPath) {
|
|
747
|
+
await (0, promises_1.mkdir)(targetDirPath, { recursive: true });
|
|
748
|
+
await (0, promises_2.pipeline)(tarball, (0, gunzip_maybe_1.default)(), (0, tar_fs_1.extract)(targetDirPath));
|
|
749
|
+
const extracted = await (0, promises_1.readdir)(targetDirPath, { withFileTypes: true });
|
|
750
|
+
if (extracted.length === 1 && extracted[0].isDirectory()) {
|
|
751
|
+
const topLevelDirPath = (0, node_path_1.join)(targetDirPath, extracted[0].name);
|
|
752
|
+
if (process.platform === 'win32') {
|
|
753
|
+
for (const childName of await (0, promises_1.readdir)(topLevelDirPath)) {
|
|
754
|
+
await (0, promises_1.rename)((0, node_path_1.join)(topLevelDirPath, childName), (0, node_path_1.join)(targetDirPath, childName));
|
|
755
|
+
}
|
|
756
|
+
await (0, promises_1.rmdir)(topLevelDirPath);
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
const tempDirPath = (0, node_path_1.join)(scratchDirPath, `.normalize-${process.pid}-${Date.now()}-${(0, node_crypto_1.randomUUID)()}`);
|
|
760
|
+
await (0, promises_1.rename)(topLevelDirPath, tempDirPath);
|
|
761
|
+
await (0, promises_1.rmdir)(targetDirPath);
|
|
762
|
+
await (0, promises_1.rename)(tempDirPath, targetDirPath);
|
|
763
|
+
return tempDirPath;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Extract an application given payload (content of the application) or package (npm-compatible identifier to the application).
|
|
770
|
+
*
|
|
771
|
+
* Only one of `application.payload` or `application.package` should be specified; otherwise, an error is thrown.
|
|
772
|
+
*
|
|
773
|
+
* Writes the application to the configured components root directory using the `application.name` and overwrites any existing directory.
|
|
774
|
+
*
|
|
775
|
+
* This method may be called from any Harper thread. Same-component calls are serialized across
|
|
776
|
+
* threads by the preparation lock below.
|
|
777
|
+
*/
|
|
778
|
+
async function extractApplication(application, deferCommit = false) {
|
|
779
|
+
// Can't specify neither
|
|
780
|
+
if (!application.payload && !application.packageIdentifier) {
|
|
781
|
+
throw new Error('Either payload or package must be provided');
|
|
782
|
+
}
|
|
783
|
+
// Can't specify both
|
|
784
|
+
if (application.payload && application.packageIdentifier) {
|
|
785
|
+
throw new Error('Both payload and package cannot be provided');
|
|
786
|
+
}
|
|
787
|
+
// Resolve the tarball from the input
|
|
788
|
+
const resolved = await resolveApplicationTarball(application);
|
|
789
|
+
if (resolved.kind === 'link') {
|
|
790
|
+
// Unchanged behavior for this path: a `file:` directory is linked in place, no extraction.
|
|
791
|
+
await (0, promises_1.symlink)(resolved.sourceDirPath, application.dirPath, 'dir');
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const { tarball, tarballPath, shouldDeleteTarball } = resolved;
|
|
795
|
+
// Replace any existing component directory atomically instead of clearing it in
|
|
796
|
+
// place. A previous version's worker can still be running and actively writing
|
|
797
|
+
// into this directory — e.g. a live Next.js app writing into `.next/cache` — and
|
|
798
|
+
// an in-place recursive rm races that writer: rm empties `.next`, then its leaf
|
|
799
|
+
// `rmdir('.next')` fails with ENOTEMPTY because the worker just re-created a cache
|
|
800
|
+
// entry. (`force: true` only suppresses ENOENT; ENOTEMPTY is not retried unless
|
|
801
|
+
// `maxRetries` is set, and a continuously-writing app would outlast retries
|
|
802
|
+
// anyway.) Renaming the old directory aside is atomic and immune to the race: the
|
|
803
|
+
// still-running worker keeps writing into the renamed inode harmlessly until it's
|
|
804
|
+
// replaced on restart. The aside remains the rollback/recovery record until commit
|
|
805
|
+
// marks it retired and cleanup removes it.
|
|
806
|
+
//
|
|
807
|
+
// The aside lives under a hidden, component-scoped staging directory inside the
|
|
808
|
+
// components root: same filesystem as the source so the rename stays atomic, the
|
|
809
|
+
// leading dot keeps loadComponentDirectories from picking it up as a phantom
|
|
810
|
+
// component, and the per-component path means a sibling component never collides
|
|
811
|
+
// with (or sweeps) another's aside.
|
|
812
|
+
const asideStagingDir = extractionStagingDirectory(application.dirPath);
|
|
813
|
+
const transactionPaths = new Set();
|
|
814
|
+
let asidePath;
|
|
815
|
+
let recoveryRecordPath;
|
|
816
|
+
try {
|
|
817
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
818
|
+
await recoverOrCleanupStaleExtractionPaths(application, asideStagingDir);
|
|
819
|
+
let componentExists = true;
|
|
820
|
+
try {
|
|
821
|
+
await (0, promises_1.lstat)(application.dirPath);
|
|
822
|
+
}
|
|
823
|
+
catch (error) {
|
|
824
|
+
if (error.code !== 'ENOENT')
|
|
825
|
+
throw error;
|
|
826
|
+
componentExists = false;
|
|
827
|
+
}
|
|
828
|
+
if (componentExists) {
|
|
829
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
830
|
+
asidePath = (0, node_path_1.join)(asideStagingDir, `${IN_PROGRESS_ASIDE_PREFIX}${Date.now()}-${process.pid}-${(0, node_crypto_1.randomUUID)()}`);
|
|
831
|
+
await (0, promises_1.rename)(application.dirPath, asidePath);
|
|
832
|
+
transactionPaths.add(asidePath);
|
|
833
|
+
recoveryRecordPath = asidePath;
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
837
|
+
recoveryRecordPath = (0, node_path_1.join)(asideStagingDir, `${IN_PROGRESS_ASIDE_PREFIX}${Date.now()}-${process.pid}-${(0, node_crypto_1.randomUUID)()}${PRIOR_ABSENT_RECORD_SUFFIX}`);
|
|
838
|
+
await (0, promises_1.writeFile)(recoveryRecordPath, '', { flag: 'wx', mode: 0o600 });
|
|
839
|
+
transactionPaths.add(recoveryRecordPath);
|
|
840
|
+
}
|
|
841
|
+
if (asidePath)
|
|
842
|
+
application.isNewComponent = false;
|
|
843
|
+
try {
|
|
844
|
+
// The scratch dir for the pack-wrapper flatten has to be on the component root's filesystem, and
|
|
845
|
+
// is a transaction path so a crash mid-flatten is cleaned up with the rest.
|
|
846
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
847
|
+
const normalizeTempPath = await extractTarballInto(tarball, application.dirPath, asideStagingDir);
|
|
848
|
+
if (normalizeTempPath)
|
|
849
|
+
transactionPaths.add(normalizeTempPath);
|
|
850
|
+
}
|
|
851
|
+
catch (error) {
|
|
852
|
+
try {
|
|
853
|
+
await rollbackExtractedDirectory(application, asideStagingDir, asidePath, transactionPaths, false);
|
|
854
|
+
}
|
|
855
|
+
catch (rollbackError) {
|
|
856
|
+
throw new AggregateError([error, rollbackError], `Failed to extract ${application.name}: ${errorMessage(error)}; ` +
|
|
857
|
+
`also failed to restore its previous component directory: ${errorMessage(rollbackError)}`);
|
|
858
|
+
}
|
|
859
|
+
throw error;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
finally {
|
|
863
|
+
if (!tarball.destroyed)
|
|
864
|
+
tarball.destroy();
|
|
865
|
+
if (shouldDeleteTarball && tarballPath) {
|
|
866
|
+
await (0, promises_1.rm)(tarballPath, { force: true }).catch((error) => application.logger.warn(`Failed to remove temporary package ${tarballPath}:`, error));
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
let settled = false;
|
|
870
|
+
const transaction = {
|
|
871
|
+
async commit() {
|
|
872
|
+
if (settled)
|
|
873
|
+
return;
|
|
874
|
+
const retiredMarkerPath = await retireExtractionAside(recoveryRecordPath);
|
|
875
|
+
transactionPaths.add(retiredMarkerPath);
|
|
876
|
+
settled = true;
|
|
877
|
+
await cleanupExtractionPaths(application, asideStagingDir, transactionPaths);
|
|
878
|
+
},
|
|
879
|
+
async rollback() {
|
|
880
|
+
if (settled)
|
|
881
|
+
return;
|
|
882
|
+
await rollbackExtractedDirectory(application, asideStagingDir, asidePath, transactionPaths, true);
|
|
883
|
+
settled = true;
|
|
884
|
+
},
|
|
885
|
+
};
|
|
886
|
+
if (deferCommit)
|
|
887
|
+
return transaction;
|
|
888
|
+
await transaction.commit();
|
|
889
|
+
}
|
|
890
|
+
// Written into a candidate's deployment directory once its build and its validation have BOTH succeeded.
|
|
891
|
+
// Roll-forward authority: recovery may activate an interrupted candidate only if this is present.
|
|
892
|
+
// Every control file is dot-prefixed, and `isJoinableComponentName` rejects a leading dot: a deployment
|
|
893
|
+
// directory holds the candidate tree under the COMPONENT'S name beside these, so an undotted name would
|
|
894
|
+
// share that namespace. A component named `activation.json` would put its tree on the journal path, the
|
|
895
|
+
// journal write would take EEXIST as "a retry of this activation", and the swap would proceed with no
|
|
896
|
+
// journal to hold the legacy pass back; one named `unsettled` would make every settle throw on a
|
|
897
|
+
// non-recursive `rm` of a directory. `assertApplicationConfig` rejects any name `isJoinableComponentName`
|
|
898
|
+
// rejects, so the collision is unreachable from a root-config key as well as from a deploy.
|
|
899
|
+
const CANDIDATE_COMPLETE_MARKER = '.complete';
|
|
900
|
+
// Records activation intent beside the candidate, so recovery finishes or undoes the whole transaction —
|
|
901
|
+
// tree and configuration together — instead of inferring intent from filesystem shape alone.
|
|
902
|
+
const ACTIVATION_JOURNAL = '.activation.json';
|
|
903
|
+
// The component this deployment directory belongs to, as plain text in its own file. Redundant with the
|
|
904
|
+
// journal on purpose: after the swap the candidate has moved to the live path, so a journal that cannot be
|
|
905
|
+
// parsed leaves nothing to infer the component from — and a failure keyed by deployment id fails NOTHING
|
|
906
|
+
// closed, letting the component load over state nobody reconciled.
|
|
907
|
+
const CANDIDATE_COMPONENT_FILE = '.component';
|
|
908
|
+
// Written by main-thread recovery when it could not settle an activation whose journal is otherwise
|
|
909
|
+
// well-formed. Workers cannot infer that case: a well-formed journal is indistinguishable from one belonging
|
|
910
|
+
// to a deploy in flight, so without a record they would treat an unsettled component as healthy and load it.
|
|
911
|
+
const UNSETTLED_MARKER = '.unsettled';
|
|
912
|
+
const ACTIVATION_JOURNAL_VERSION = 1;
|
|
913
|
+
/**
|
|
914
|
+
* Best-effort fsync of a directory. Best-effort by necessity — Node cannot fsync a directory on Windows —
|
|
915
|
+
* which is why roll-forward requires journal + candidate + complete marker to all be observable: a lost
|
|
916
|
+
* directory update then degrades to a roll back, never to a wrong decision. See DESIGN.md.
|
|
917
|
+
*/
|
|
918
|
+
async function syncDirectory(dirPath) {
|
|
919
|
+
let handle;
|
|
920
|
+
try {
|
|
921
|
+
handle = await (0, promises_1.open)(dirPath, 'r');
|
|
922
|
+
}
|
|
923
|
+
catch (error) {
|
|
924
|
+
// Same split as `sync` below and as the file path: Windows cannot open a directory for fsync at all,
|
|
925
|
+
// and a directory removed by cleanup is not a fault either — but an EIO opening it is.
|
|
926
|
+
if (!isUnsupportedSync(error) && error?.code !== 'ENOENT')
|
|
927
|
+
throw error;
|
|
928
|
+
harper_logger_ts_1.default.trace?.(`Directory sync of ${dirPath} unavailable: ${errorMessage(error)}`);
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
try {
|
|
932
|
+
await handle.sync();
|
|
933
|
+
}
|
|
934
|
+
catch (error) {
|
|
935
|
+
// A platform that will not sync directories is tolerated, a storage failure is not: suppressing
|
|
936
|
+
// EIO/ENOSPC here would let a lost directory entry look durable. The `finally` closes the handle.
|
|
937
|
+
if (!isUnsupportedSync(error))
|
|
938
|
+
throw error;
|
|
939
|
+
harper_logger_ts_1.default.trace?.(`Directory sync of ${dirPath} unsupported: ${errorMessage(error)}`);
|
|
940
|
+
}
|
|
941
|
+
finally {
|
|
942
|
+
// Swallowed: this runs outside any compensation block, so a rejecting close would surface as an
|
|
943
|
+
// activation failure for something already best-effort.
|
|
944
|
+
await handle.close().catch((error) => harper_logger_ts_1.default.trace?.(`Closing ${dirPath} failed: ${errorMessage(error)}`));
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* A rename changes an entry in BOTH parents, so both are synced: a surviving source entry reads as
|
|
949
|
+
* "candidate still there" and would roll an already-completed activation forward twice.
|
|
950
|
+
*/
|
|
951
|
+
async function syncRenameParents(fromPath, toPath) {
|
|
952
|
+
const parents = new Set([(0, node_path_1.dirname)(fromPath), (0, node_path_1.dirname)(toPath)]);
|
|
953
|
+
for (const parent of parents)
|
|
954
|
+
await syncDirectory(parent);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Write a control file so its final name NEVER exists with partial contents. Opening the final path with
|
|
958
|
+
* `wx` publishes the directory entry before anything is written, so a crash in between leaves a zero-byte
|
|
959
|
+
* file — which for the journal means "unreadable", failing a component closed over a deploy that had not
|
|
960
|
+
* actually started. Contents land in a temp name, are fsynced, and only then renamed into place.
|
|
961
|
+
*/
|
|
962
|
+
async function writeControlFileDurably(filePath, contents) {
|
|
963
|
+
const tempPath = `${filePath}.partial-${process.pid}-${(0, node_crypto_1.randomUUID)()}`;
|
|
964
|
+
const handle = await (0, promises_1.open)(tempPath, 'wx', 0o600);
|
|
965
|
+
try {
|
|
966
|
+
await handle.writeFile(contents, 'utf8');
|
|
967
|
+
await handle.sync();
|
|
968
|
+
}
|
|
969
|
+
finally {
|
|
970
|
+
await handle.close();
|
|
971
|
+
}
|
|
972
|
+
try {
|
|
973
|
+
// `wx` on the temp name plus this rename keeps the EEXIST semantics callers rely on to detect a
|
|
974
|
+
// retry of the same activation.
|
|
975
|
+
await (0, promises_1.link)(tempPath, filePath);
|
|
976
|
+
}
|
|
977
|
+
finally {
|
|
978
|
+
await (0, promises_1.rm)(tempPath, { force: true });
|
|
979
|
+
}
|
|
980
|
+
await syncDirectory((0, node_path_1.dirname)(filePath));
|
|
981
|
+
}
|
|
982
|
+
function candidateCompleteMarkerPath(componentDirPath, deploymentId) {
|
|
983
|
+
return (0, node_path_1.join)(candidateDeploymentDirPath(componentDirPath, deploymentId), CANDIDATE_COMPLETE_MARKER);
|
|
984
|
+
}
|
|
985
|
+
function candidateComponentFilePath(componentDirPath, deploymentId) {
|
|
986
|
+
return (0, node_path_1.join)(candidateDeploymentDirPath(componentDirPath, deploymentId), CANDIDATE_COMPONENT_FILE);
|
|
987
|
+
}
|
|
988
|
+
function activationJournalPath(componentDirPath, deploymentId) {
|
|
989
|
+
return (0, node_path_1.join)(candidateDeploymentDirPath(componentDirPath, deploymentId), ACTIVATION_JOURNAL);
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* A component name safe to join onto the components root: no separator, no traversal, not dot-prefixed.
|
|
993
|
+
* Applied to EVERY source of the name — the journal and the sidecar — because validating one and trusting
|
|
994
|
+
* the other is how a corrupt record reaches an unrelated directory.
|
|
995
|
+
*/
|
|
996
|
+
function isJoinableComponentName(name) {
|
|
997
|
+
return (typeof name === 'string' &&
|
|
998
|
+
name.length > 0 &&
|
|
999
|
+
name === (0, node_path_1.basename)(name) &&
|
|
1000
|
+
name !== '.' &&
|
|
1001
|
+
name !== '..' &&
|
|
1002
|
+
!name.startsWith('.'));
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Read an activation journal. Absent is `undefined` — no activation was attempted. Anything else THROWS:
|
|
1006
|
+
* a truncated or unknown-version journal is an interrupted activation whose intent cannot be read, and
|
|
1007
|
+
* both guesses are destructive (publish a rejected release, or discard a good one), so the component is
|
|
1008
|
+
* failed closed instead.
|
|
1009
|
+
*/
|
|
1010
|
+
async function readActivationJournal(journalPath) {
|
|
1011
|
+
let raw;
|
|
1012
|
+
try {
|
|
1013
|
+
raw = await (0, promises_1.readFile)(journalPath, 'utf8');
|
|
1014
|
+
}
|
|
1015
|
+
catch (error) {
|
|
1016
|
+
if (error.code === 'ENOENT')
|
|
1017
|
+
return undefined;
|
|
1018
|
+
throw error;
|
|
1019
|
+
}
|
|
1020
|
+
let parsed;
|
|
1021
|
+
try {
|
|
1022
|
+
parsed = JSON.parse(raw);
|
|
1023
|
+
}
|
|
1024
|
+
catch (error) {
|
|
1025
|
+
throw new Error(`Activation journal ${journalPath} could not be parsed: ${errorMessage(error)}`);
|
|
1026
|
+
}
|
|
1027
|
+
if (parsed?.v !== ACTIVATION_JOURNAL_VERSION) {
|
|
1028
|
+
throw new Error(`Activation journal ${journalPath} has version ${JSON.stringify(parsed?.v)}, expected ${ACTIVATION_JOURNAL_VERSION}`);
|
|
1029
|
+
}
|
|
1030
|
+
if (!isJoinableComponentName(parsed.component) || typeof parsed.candidateId !== 'string') {
|
|
1031
|
+
throw new Error(`Activation journal ${journalPath} does not identify its component and candidate`);
|
|
1032
|
+
}
|
|
1033
|
+
// The journal must describe the directory it sits in. A syntactically valid journal naming someone
|
|
1034
|
+
// else's deployment would otherwise let recovery act on a component from the wrong record.
|
|
1035
|
+
if (parsed.candidateId !== (0, node_path_1.basename)((0, node_path_1.dirname)(journalPath))) {
|
|
1036
|
+
throw new Error(`Activation journal ${journalPath} names candidate '${parsed.candidateId}', which is not its own deployment`);
|
|
1037
|
+
}
|
|
1038
|
+
return parsed;
|
|
1039
|
+
}
|
|
1040
|
+
/** The deployment directory holding one candidate build: `<root>/.deploy-staging/<deploymentId>`. */
|
|
1041
|
+
function candidateDeploymentDirPath(componentDirPath, deploymentId) {
|
|
1042
|
+
return (0, node_path_1.join)((0, node_path_1.dirname)(componentDirPath), exports.DEPLOY_STAGING_DIR, deploymentId);
|
|
1043
|
+
}
|
|
1044
|
+
/** Where a candidate build lives: `<root>/.deploy-staging/<deploymentId>/<component>`. */
|
|
1045
|
+
function candidateApplicationPath(componentDirPath, deploymentId) {
|
|
1046
|
+
return (0, node_path_1.join)(candidateDeploymentDirPath(componentDirPath, deploymentId), (0, node_path_1.basename)(componentDirPath));
|
|
1047
|
+
}
|
|
1048
|
+
function extractionStagingDirectory(componentDirPath) {
|
|
1049
|
+
return (0, node_path_1.join)((0, node_path_1.dirname)(componentDirPath), exports.ASIDE_STAGING_DIR, (0, node_path_1.basename)(componentDirPath));
|
|
1050
|
+
}
|
|
1051
|
+
function retiredMarkerForAside(asidePath) {
|
|
1052
|
+
return (0, node_path_1.join)((0, node_path_1.dirname)(asidePath), `${RETIRED_ASIDE_PREFIX}${(0, node_path_1.basename)(asidePath).slice(IN_PROGRESS_ASIDE_PREFIX.length)}`);
|
|
1053
|
+
}
|
|
1054
|
+
async function retireExtractionAside(asidePath) {
|
|
1055
|
+
const retiredMarkerPath = retiredMarkerForAside(asidePath);
|
|
1056
|
+
try {
|
|
1057
|
+
await (0, promises_1.writeFile)(retiredMarkerPath, '', { flag: 'wx', mode: 0o600 });
|
|
1058
|
+
}
|
|
1059
|
+
catch (error) {
|
|
1060
|
+
if (error.code !== 'EEXIST')
|
|
1061
|
+
throw error;
|
|
1062
|
+
}
|
|
1063
|
+
return retiredMarkerPath;
|
|
1064
|
+
}
|
|
1065
|
+
function errorMessage(error) {
|
|
1066
|
+
return error instanceof Error ? error.message : String(error);
|
|
1067
|
+
}
|
|
1068
|
+
async function makeRollbackPlaceholderMovable(applicationDirPath, placeholderIdentity) {
|
|
1069
|
+
if (!placeholderIdentity)
|
|
1070
|
+
return;
|
|
1071
|
+
try {
|
|
1072
|
+
const current = await (0, promises_1.lstat)(applicationDirPath, { bigint: true });
|
|
1073
|
+
if (current.dev === placeholderIdentity.dev && current.ino === placeholderIdentity.ino) {
|
|
1074
|
+
await (0, promises_1.chmod)(applicationDirPath, 0o700);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
catch (error) {
|
|
1078
|
+
if (error.code !== 'ENOENT')
|
|
1079
|
+
throw error;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
async function identifyRollbackPlaceholder(applicationDirPath) {
|
|
1083
|
+
const userId = process.getuid?.();
|
|
1084
|
+
if (process.platform === 'win32' || userId === undefined || userId === 0)
|
|
1085
|
+
return undefined;
|
|
1086
|
+
try {
|
|
1087
|
+
const current = await (0, promises_1.lstat)(applicationDirPath, { bigint: true });
|
|
1088
|
+
const permissions = Number(current.mode) & 0o777;
|
|
1089
|
+
if ((current.isDirectory() || current.isFile()) &&
|
|
1090
|
+
current.uid === BigInt(userId) &&
|
|
1091
|
+
(permissions === 0 || (current.isDirectory() && (permissions === 0o100 || permissions === 0o300)))) {
|
|
1092
|
+
return { dev: current.dev, ino: current.ino };
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
if (error.code !== 'ENOENT')
|
|
1097
|
+
throw error;
|
|
1098
|
+
}
|
|
1099
|
+
return undefined;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Create a hidden staging directory and confirm it is the one we created: a real directory rather than a
|
|
1103
|
+
* symlink or junction substituted underneath us, restricted to the owner. Re-checked at every use rather
|
|
1104
|
+
* than once per deploy, because the gap between checking and writing is the exploitable part.
|
|
1105
|
+
*/
|
|
1106
|
+
async function ensureSecureStagingDirectory(stagingDir) {
|
|
1107
|
+
await (0, promises_1.mkdir)(stagingDir, { recursive: true, mode: 0o700 });
|
|
1108
|
+
const stagingStat = await (0, promises_1.lstat)(stagingDir);
|
|
1109
|
+
if (!stagingStat.isDirectory() || stagingStat.isSymbolicLink()) {
|
|
1110
|
+
throw new Error(`Component deploy staging path is not a directory: ${stagingDir}`);
|
|
1111
|
+
}
|
|
1112
|
+
if (process.platform !== 'win32' && (stagingStat.mode & 0o777) !== 0o700) {
|
|
1113
|
+
await (0, promises_1.chmod)(stagingDir, 0o700).catch((error) => harper_logger_ts_1.default.warn(`Could not restrict component deploy staging permissions for ${stagingDir}:`, (0, harper_logger_ts_1.errorForLog)(error)));
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
async function ensureExtractionStagingDirectory(asideStagingDir) {
|
|
1117
|
+
for (const stagingDir of [(0, node_path_1.dirname)(asideStagingDir), asideStagingDir]) {
|
|
1118
|
+
await ensureSecureStagingDirectory(stagingDir);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
/** The single component directory inside a candidate deployment directory, when there is exactly one. */
|
|
1122
|
+
async function candidateComponentName(deploymentDirPath) {
|
|
1123
|
+
// The sidecar first: it is the only source that still works once the candidate has been renamed to the
|
|
1124
|
+
// live path, which is exactly when an unreadable journal would otherwise be unattributable.
|
|
1125
|
+
// Only ENOENT is absence. Swallowing every error here reported "unowned", which is a licence to act:
|
|
1126
|
+
// the worker verdict dropped a failure and loaded a component main had failed closed, and a deploy
|
|
1127
|
+
// skipped a journaled activation it owns and stalled the component in the legacy pass instead.
|
|
1128
|
+
const recorded = await (0, promises_1.readFile)((0, node_path_1.join)(deploymentDirPath, CANDIDATE_COMPONENT_FILE), 'utf8').catch((error) => {
|
|
1129
|
+
if (error?.code === 'ENOENT')
|
|
1130
|
+
return '';
|
|
1131
|
+
throw error;
|
|
1132
|
+
});
|
|
1133
|
+
const named = recorded.trim();
|
|
1134
|
+
if (isJoinableComponentName(named))
|
|
1135
|
+
return named;
|
|
1136
|
+
const entries = await (0, promises_1.readdir)(deploymentDirPath, { withFileTypes: true }).catch((error) => {
|
|
1137
|
+
if (error?.code === 'ENOENT')
|
|
1138
|
+
return [];
|
|
1139
|
+
throw error;
|
|
1140
|
+
});
|
|
1141
|
+
// Symlinks count: a `file:<directory>` candidate is deliberately a link, and activation already accepts
|
|
1142
|
+
// one. Filtering to real directories here left those candidates with no owner, so residue removal took
|
|
1143
|
+
// no lock and could delete a build in flight.
|
|
1144
|
+
//
|
|
1145
|
+
// Validated, because this infers an owner from a NAME. A directory-shaped control file — a corrupt
|
|
1146
|
+
// `.activation.json` that is a directory — would otherwise be returned as the owning component, which
|
|
1147
|
+
// both licenses a restore against it and is a name no component can have.
|
|
1148
|
+
const components = entries.filter((entry) => (entry.isDirectory() || entry.isSymbolicLink()) && isJoinableComponentName(entry.name));
|
|
1149
|
+
return components.length === 1 ? components[0].name : undefined;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* The deployment directory of an activation journal this component still owns, if any.
|
|
1153
|
+
*
|
|
1154
|
+
* The journal is the authority for an interrupted activation. The legacy `.deploy-aside` pass would
|
|
1155
|
+
* otherwise restore the displaced tree over a candidate a completed activation already renamed live, so it
|
|
1156
|
+
* consults this before restoring rather than relying on being sequenced after settlement: a worker
|
|
1157
|
+
* auto-restarted mid-activation reaches it with no settlement in front of it, and settlement that FAILS
|
|
1158
|
+
* deliberately keeps the journal for the next start while the same boot carries on into the legacy pass.
|
|
1159
|
+
*/
|
|
1160
|
+
async function journaledDeploymentForComponent(componentsRootDirPath, componentName) {
|
|
1161
|
+
const stagingRoot = (0, node_path_1.join)(componentsRootDirPath, exports.DEPLOY_STAGING_DIR);
|
|
1162
|
+
let deployments;
|
|
1163
|
+
try {
|
|
1164
|
+
deployments = await (0, promises_1.readdir)(stagingRoot, { withFileTypes: true });
|
|
1165
|
+
}
|
|
1166
|
+
catch (error) {
|
|
1167
|
+
if (error.code === 'ENOENT')
|
|
1168
|
+
return undefined;
|
|
1169
|
+
throw error;
|
|
1170
|
+
}
|
|
1171
|
+
for (const deployment of deployments) {
|
|
1172
|
+
if (!deployment.isDirectory())
|
|
1173
|
+
continue;
|
|
1174
|
+
const deploymentDirPath = (0, node_path_1.join)(stagingRoot, deployment.name);
|
|
1175
|
+
const journalPath = (0, node_path_1.join)(deploymentDirPath, ACTIVATION_JOURNAL);
|
|
1176
|
+
// NOTHING is swallowed here. This is the gate that authorizes restoring an old tree over what may be
|
|
1177
|
+
// a committed candidate, so "could not tell" has to fail closed — treating an unreadable deployment
|
|
1178
|
+
// as "no journal for this component" is exactly the clobber the journal exists to prevent. The blast
|
|
1179
|
+
// radius is narrow because the gate is only consulted where a restorable record already exists.
|
|
1180
|
+
//
|
|
1181
|
+
// Presence, not parseability: an unreadable journal is precisely the ambiguous case.
|
|
1182
|
+
const journaled = await (0, promises_1.lstat)(journalPath).then(() => true, (error) => {
|
|
1183
|
+
if (error.code === 'ENOENT')
|
|
1184
|
+
return false;
|
|
1185
|
+
throw error;
|
|
1186
|
+
});
|
|
1187
|
+
if (!journaled)
|
|
1188
|
+
continue;
|
|
1189
|
+
// EITHER name blocks, while settlement acts only when both agree. The destructive step takes the
|
|
1190
|
+
// conservative union; the corrective one takes the precise intersection, so a journal whose two
|
|
1191
|
+
// attributions disagree stalls the restore instead of licensing it, and startup recovery — which
|
|
1192
|
+
// keys on the journal — is what clears it. The sidecar also covers a component legitimately named
|
|
1193
|
+
// `component`, whose candidate path collides with the sidecar's and makes every sidecar read fail.
|
|
1194
|
+
const journalOwner = (await readActivationJournal(journalPath).catch(() => undefined))?.component;
|
|
1195
|
+
if (journalOwner === componentName)
|
|
1196
|
+
return deploymentDirPath;
|
|
1197
|
+
const sidecarOwner = await candidateComponentName(deploymentDirPath);
|
|
1198
|
+
if (sidecarOwner === componentName)
|
|
1199
|
+
return deploymentDirPath;
|
|
1200
|
+
// A journal nobody can attribute blocks EVERY component. It is a rare, genuinely broken state — an
|
|
1201
|
+
// unparseable journal whose deployment no longer holds a tree to infer from — and the alternative is
|
|
1202
|
+
// letting the restore proceed against a candidate this journal may well have committed. There is no
|
|
1203
|
+
// automated way out of it, by construction: nothing on disk says which component it belongs to. The
|
|
1204
|
+
// error the caller raises names the directory an operator has to resolve.
|
|
1205
|
+
if (journalOwner === undefined && sidecarOwner === undefined)
|
|
1206
|
+
return deploymentDirPath;
|
|
1207
|
+
}
|
|
1208
|
+
return undefined;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* The components a deployment's evidence implicates, when its journal and its ownership sidecar disagree
|
|
1212
|
+
* about whose it is — or `undefined` when there is no disagreement to act on.
|
|
1213
|
+
*
|
|
1214
|
+
* A sidecar that cannot answer is NOT disagreement: the journal names its own component and can settle it,
|
|
1215
|
+
* so an unreadable sidecar must not block that. Only a sidecar that reads and names something else is the
|
|
1216
|
+
* wedge, and then BOTH names are returned, sidecar first, because both are stuck — see
|
|
1217
|
+
* `splitAttributionError`.
|
|
1218
|
+
*
|
|
1219
|
+
* Separated from either call site so the decision is testable on its own: the paths that reach it include
|
|
1220
|
+
* one that requires a journal to appear between two reads under a lock, which no test can stage.
|
|
1221
|
+
*/
|
|
1222
|
+
function splitAttributionOwners(journalOwner, sidecarOwner) {
|
|
1223
|
+
if (sidecarOwner === undefined || sidecarOwner === journalOwner)
|
|
1224
|
+
return undefined;
|
|
1225
|
+
return [sidecarOwner, journalOwner];
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* The error for a deployment its journal and its ownership sidecar attribute to different components.
|
|
1229
|
+
*
|
|
1230
|
+
* Both names are wedged, so both are failed: the restore gate takes the union and blocks the sidecar's
|
|
1231
|
+
* component, while settlement needs the intersection and so can never clear the journal owner's. Neither
|
|
1232
|
+
* component's own deploy can resolve it, which is why the message names the directory to remove.
|
|
1233
|
+
*/
|
|
1234
|
+
function splitAttributionError(deploymentDirPath, journalOwner, sidecarOwner) {
|
|
1235
|
+
return new Error(`Deploy staging ${deploymentDirPath} is attributed to two different components: its journal names ` +
|
|
1236
|
+
`'${journalOwner}' and its sidecar names '${sidecarOwner}'. Neither can settle it; remove that ` +
|
|
1237
|
+
`directory once you have determined which tree is current.`);
|
|
1238
|
+
}
|
|
1239
|
+
/** In-progress rollback records in a component's aside directory, newest first. */
|
|
1240
|
+
async function inProgressAsideRecords(asideStagingDir) {
|
|
1241
|
+
// ENOENT is "no aside directory yet"; anything else would report "no records" and let roll-forward
|
|
1242
|
+
// remove the journal while the records it should have retired are still there and still authoritative.
|
|
1243
|
+
const entries = await (0, promises_1.readdir)(asideStagingDir, { withFileTypes: true }).catch((error) => {
|
|
1244
|
+
if (error?.code === 'ENOENT')
|
|
1245
|
+
return [];
|
|
1246
|
+
throw error;
|
|
1247
|
+
});
|
|
1248
|
+
// Retired records excluded, the same rule `recoverOrCleanupStaleExtractionPaths` applies. A record whose
|
|
1249
|
+
// retire succeeded but whose best-effort sweep did not is settled, not displaced — counting it would let
|
|
1250
|
+
// an ordinary pre-swap state look like the "live path recreated" ambiguity and fail a healthy component
|
|
1251
|
+
// closed with an operator-only exit.
|
|
1252
|
+
const entryNames = new Set(entries.map((entry) => entry.name));
|
|
1253
|
+
return entries
|
|
1254
|
+
.filter((entry) => entry.name.startsWith(IN_PROGRESS_ASIDE_PREFIX) &&
|
|
1255
|
+
!entryNames.has(`${RETIRED_ASIDE_PREFIX}${entry.name.slice(IN_PROGRESS_ASIDE_PREFIX.length)}`))
|
|
1256
|
+
.map((entry) => (0, node_path_1.join)(asideStagingDir, entry.name))
|
|
1257
|
+
.sort()
|
|
1258
|
+
.reverse();
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Settle journaled activations for ONE component, assuming the caller already holds its preparation lock.
|
|
1262
|
+
*
|
|
1263
|
+
* Exists because the journal-first rule has to hold at every entry point, not just startup. A deploy runs
|
|
1264
|
+
* `recoverOrCleanupStaleExtractionPaths` first. After an activation whose retirement failed, the aside
|
|
1265
|
+
* still names the DISPLACED tree, so restoring it would put the old version back over the new one. That
|
|
1266
|
+
* pass refuses to restore against a surviving journal, but refusing is a stalled component; settling first
|
|
1267
|
+
* is what lets the deploy proceed.
|
|
1268
|
+
*/
|
|
1269
|
+
async function settleJournaledActivationsForComponent(componentsRootDirPath, componentName) {
|
|
1270
|
+
const stagingRoot = (0, node_path_1.join)(componentsRootDirPath, exports.DEPLOY_STAGING_DIR);
|
|
1271
|
+
let deployments;
|
|
1272
|
+
try {
|
|
1273
|
+
deployments = await (0, promises_1.readdir)(stagingRoot, { withFileTypes: true });
|
|
1274
|
+
}
|
|
1275
|
+
catch (error) {
|
|
1276
|
+
if (error.code === 'ENOENT')
|
|
1277
|
+
return;
|
|
1278
|
+
throw error;
|
|
1279
|
+
}
|
|
1280
|
+
for (const deployment of deployments) {
|
|
1281
|
+
if (!deployment.isDirectory())
|
|
1282
|
+
continue;
|
|
1283
|
+
const deploymentDirPath = (0, node_path_1.join)(stagingRoot, deployment.name);
|
|
1284
|
+
// Ownership BEFORE parsing. Reading every journal first meant a truncated journal belonging to another
|
|
1285
|
+
// component threw here — blocking the deploy of a healthy component because an unrelated one is
|
|
1286
|
+
// broken. The sidecar names the owner without parsing anything, and a deployment that does not name
|
|
1287
|
+
// this component is none of this deploy's business; startup recovery reports it instead.
|
|
1288
|
+
//
|
|
1289
|
+
// An ownership read that FAILS is the same situation, and skipping is safe here specifically because
|
|
1290
|
+
// settlement is the corrective half: if that entry does turn out to be this component's, the restore
|
|
1291
|
+
// gate — which takes the union and fails closed on anything it cannot attribute — is what stops the
|
|
1292
|
+
// legacy pass acting on it. Failing the deploy instead lets one unreadable sibling block every
|
|
1293
|
+
// neighbour's deploys, which is the outage this ordering exists to prevent.
|
|
1294
|
+
let owner;
|
|
1295
|
+
let ownerUnreadable = false;
|
|
1296
|
+
try {
|
|
1297
|
+
owner = await candidateComponentName(deploymentDirPath);
|
|
1298
|
+
}
|
|
1299
|
+
catch (error) {
|
|
1300
|
+
ownerUnreadable = true;
|
|
1301
|
+
harper_logger_ts_1.default.trace?.(`Ownership of ${deploymentDirPath} is unreadable while settling ${componentName}, falling back to ` +
|
|
1302
|
+
`its journal: ${errorMessage(error)}`);
|
|
1303
|
+
}
|
|
1304
|
+
if (!ownerUnreadable && owner !== componentName)
|
|
1305
|
+
continue;
|
|
1306
|
+
const journal = await readActivationJournal((0, node_path_1.join)(deploymentDirPath, ACTIVATION_JOURNAL));
|
|
1307
|
+
// A journal-less directory is what a SUCCESSFUL settlement leaves when its best-effort sweep fails, so
|
|
1308
|
+
// this must not fail closed. An unattributable *activation* still does: `readActivationJournal` throws
|
|
1309
|
+
// on a journal that exists but cannot be read.
|
|
1310
|
+
if (!journal)
|
|
1311
|
+
continue;
|
|
1312
|
+
// The journal decides, not the sidecar. Skipping on an unreadable sidecar alone would leave this
|
|
1313
|
+
// component's own unsettled activation in place while a new deploy proceeded over it, and an
|
|
1314
|
+
// activation interrupted before B1 has no rollback record for the restore gate to catch.
|
|
1315
|
+
if (journal.component !== componentName)
|
|
1316
|
+
continue;
|
|
1317
|
+
await settleInterruptedActivation(componentsRootDirPath, deploymentDirPath, journal);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Components that on-disk evidence says were left in a state nobody settled — determined READ-ONLY, so any
|
|
1322
|
+
* thread can reach the same verdict.
|
|
1323
|
+
*
|
|
1324
|
+
* Recovery runs on the main thread only, but the components it could not settle still have to be failed
|
|
1325
|
+
* closed on the workers that actually serve them, and a worker cannot be handed main's verdict: it boots
|
|
1326
|
+
* through its own `loadRootComponents(true)`, potentially before main finished. Recovery deliberately KEEPS
|
|
1327
|
+
* the evidence for anything it could not settle, so a worker can read it instead of being told.
|
|
1328
|
+
*
|
|
1329
|
+
* Only unambiguous evidence counts. A well-formed journal is NOT evidence — every healthy deploy has one
|
|
1330
|
+
* in flight — so this reports a journal that cannot be read at all (corrupt, unknown version, or naming
|
|
1331
|
+
* something other than its own deployment), which no in-flight deploy ever produces.
|
|
1332
|
+
*/
|
|
1333
|
+
async function unsettleableComponentsFromDisk(componentsRootDirPath) {
|
|
1334
|
+
const unsettleable = new Map();
|
|
1335
|
+
const stagingRoot = (0, node_path_1.join)(componentsRootDirPath, exports.DEPLOY_STAGING_DIR);
|
|
1336
|
+
let deployments;
|
|
1337
|
+
try {
|
|
1338
|
+
deployments = await (0, promises_1.readdir)(stagingRoot, { withFileTypes: true });
|
|
1339
|
+
}
|
|
1340
|
+
catch (error) {
|
|
1341
|
+
if (error.code === 'ENOENT')
|
|
1342
|
+
return unsettleable;
|
|
1343
|
+
throw error;
|
|
1344
|
+
}
|
|
1345
|
+
for (const deployment of deployments) {
|
|
1346
|
+
if (!deployment.isDirectory())
|
|
1347
|
+
continue;
|
|
1348
|
+
const deploymentDirPath = (0, node_path_1.join)(stagingRoot, deployment.name);
|
|
1349
|
+
// Per deployment. `candidateComponentName` propagates every non-ENOENT error now, and this pass runs
|
|
1350
|
+
// where the CALLER only warns — so one unreadable deployment escaping here would drop the verdict for
|
|
1351
|
+
// every other component and let each of them load with no evidence checked at all.
|
|
1352
|
+
try {
|
|
1353
|
+
await verdictFor(deploymentDirPath, deployment.name, unsettleable);
|
|
1354
|
+
}
|
|
1355
|
+
catch (error) {
|
|
1356
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1357
|
+
if (!unsettleable.has(deployment.name))
|
|
1358
|
+
unsettleable.set(deployment.name, failure);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return unsettleable;
|
|
1362
|
+
}
|
|
1363
|
+
/** One deployment's read-only verdict. Throws rather than guessing; the caller scopes that to this entry. */
|
|
1364
|
+
async function verdictFor(deploymentDirPath, deploymentName, unsettleable) {
|
|
1365
|
+
// Recorded by main when it failed to settle a well-formed journal. Checked first, because that case is
|
|
1366
|
+
// invisible to a worker otherwise.
|
|
1367
|
+
//
|
|
1368
|
+
// Only ENOENT is absence. A marker that exists but cannot be read (EIO, EACCES) must not be taken as
|
|
1369
|
+
// "no verdict" — that classifies the well-formed journal beside it as a healthy in-flight deploy and
|
|
1370
|
+
// lets the worker load a component main failed closed.
|
|
1371
|
+
let recorded;
|
|
1372
|
+
try {
|
|
1373
|
+
recorded = await (0, promises_1.readFile)((0, node_path_1.join)(deploymentDirPath, UNSETTLED_MARKER), 'utf8');
|
|
1374
|
+
}
|
|
1375
|
+
catch (error) {
|
|
1376
|
+
if (error.code !== 'ENOENT') {
|
|
1377
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1378
|
+
return record(unsettleable, await attribute(deploymentDirPath, deploymentName), failure);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
if (recorded !== undefined) {
|
|
1382
|
+
const component = await attribute(deploymentDirPath, deploymentName);
|
|
1383
|
+
return record(unsettleable, component, new Error(recorded.trim() || `Activation of ${component} could not be settled`));
|
|
1384
|
+
}
|
|
1385
|
+
try {
|
|
1386
|
+
await readActivationJournal((0, node_path_1.join)(deploymentDirPath, ACTIVATION_JOURNAL));
|
|
1387
|
+
}
|
|
1388
|
+
catch (error) {
|
|
1389
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1390
|
+
record(unsettleable, await attribute(deploymentDirPath, deploymentName), failure);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Who a deployment's evidence belongs to. Falls back to the deployment id when nothing names it: a verdict
|
|
1395
|
+
* attributed to nothing is a verdict nobody acts on, and the id is at least something an operator can find
|
|
1396
|
+
* on disk. A read that FAILS is not "nothing names it" — that propagates, and the caller records it against
|
|
1397
|
+
* the id, so an unreadable deployment is reported rather than dropped.
|
|
1398
|
+
*/
|
|
1399
|
+
async function attribute(deploymentDirPath, deploymentName) {
|
|
1400
|
+
return (await candidateComponentName(deploymentDirPath)) ?? deploymentName;
|
|
1401
|
+
}
|
|
1402
|
+
function record(unsettleable, component, failure) {
|
|
1403
|
+
if (!unsettleable.has(component))
|
|
1404
|
+
unsettleable.set(component, failure);
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Settle activations a crash interrupted, before anything loads. Runs at startup on main and on every
|
|
1408
|
+
* worker — a worker can be respawned mid-activation, long after main's pass.
|
|
1409
|
+
*
|
|
1410
|
+
* Returns failures keyed by COMPONENT so the caller can fail exactly those closed and still load every
|
|
1411
|
+
* healthy sibling — a single unreadable journal must not take down the whole node, and must not let a
|
|
1412
|
+
* component load over state nobody reconciled.
|
|
1413
|
+
*
|
|
1414
|
+
*/
|
|
1415
|
+
async function recoverInterruptedActivations(componentsRootDirPath) {
|
|
1416
|
+
const failures = new Map();
|
|
1417
|
+
const stagingRoot = (0, node_path_1.join)(componentsRootDirPath, exports.DEPLOY_STAGING_DIR);
|
|
1418
|
+
let deployments;
|
|
1419
|
+
try {
|
|
1420
|
+
deployments = await (0, promises_1.readdir)(stagingRoot, { withFileTypes: true });
|
|
1421
|
+
}
|
|
1422
|
+
catch (error) {
|
|
1423
|
+
if (error.code === 'ENOENT')
|
|
1424
|
+
return failures;
|
|
1425
|
+
throw error;
|
|
1426
|
+
}
|
|
1427
|
+
for (const deployment of deployments) {
|
|
1428
|
+
if (!deployment.isDirectory())
|
|
1429
|
+
continue;
|
|
1430
|
+
const deploymentDirPath = (0, node_path_1.join)(stagingRoot, deployment.name);
|
|
1431
|
+
const journalPath = (0, node_path_1.join)(deploymentDirPath, ACTIVATION_JOURNAL);
|
|
1432
|
+
const fail = async (component, error) => {
|
|
1433
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1434
|
+
if (!failures.has(component))
|
|
1435
|
+
failures.set(component, failure);
|
|
1436
|
+
harper_logger_ts_1.default.error(`Could not settle the interrupted activation of ${component}:`, (0, harper_logger_ts_1.errorForLog)(failure));
|
|
1437
|
+
// A DEFERRAL is not a verdict, and only verdicts go on disk. A held lock means a live deploy, which
|
|
1438
|
+
// settles its own journal; a marker written here would outlive that deploy and have
|
|
1439
|
+
// `unsettleableComponentsFromDisk` read it as an authoritative "cannot be settled", failing a
|
|
1440
|
+
// healthy component closed on every worker. The failure is already recorded above, so this thread
|
|
1441
|
+
// still defers — it just leaves nothing behind.
|
|
1442
|
+
if (failure instanceof componentPreparationLock_ts_1.ComponentPreparationLockTimeoutError)
|
|
1443
|
+
return;
|
|
1444
|
+
// Everything else IS a verdict, recorded so workers reach the same one. An unreadable journal is
|
|
1445
|
+
// self-evident, but a well-formed journal this pass could not settle looks exactly like a deploy
|
|
1446
|
+
// in flight, and a worker would otherwise load the component over state nobody reconciled.
|
|
1447
|
+
// Best-effort: the alternative to a missing marker is today's behavior, not a worse one.
|
|
1448
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(deploymentDirPath, UNSETTLED_MARKER), failure.message, { mode: 0o600 }).catch((markerError) => harper_logger_ts_1.default.warn(`Could not record the unsettled activation of ${component}: ${errorMessage(markerError)}`));
|
|
1449
|
+
};
|
|
1450
|
+
let journal;
|
|
1451
|
+
try {
|
|
1452
|
+
journal = await readActivationJournal(journalPath);
|
|
1453
|
+
}
|
|
1454
|
+
catch (error) {
|
|
1455
|
+
// The journal itself is unreadable, so its component has to be inferred from the tree it was
|
|
1456
|
+
// going to activate. A deployment directory holding no component tree leaves only its id.
|
|
1457
|
+
const attributed = await candidateComponentName(deploymentDirPath).catch(() => undefined);
|
|
1458
|
+
await fail(attributed ?? deployment.name, error);
|
|
1459
|
+
continue;
|
|
1460
|
+
}
|
|
1461
|
+
if (!journal) {
|
|
1462
|
+
// No activation was attempted: build residue, or a candidate abandoned mid-build. The legacy
|
|
1463
|
+
// in-place recovery owns any aside it left, so there is nothing to settle.
|
|
1464
|
+
//
|
|
1465
|
+
// Removed UNDER the component's lock, and only after re-checking that no journal appeared in the
|
|
1466
|
+
// meantime. A reload cycle can run this pass while another deploy is mid-build — its candidate
|
|
1467
|
+
// has no journal yet, because the journal is written after build and validation — so an unlocked
|
|
1468
|
+
// delete here removes a live build out from under it.
|
|
1469
|
+
let owner;
|
|
1470
|
+
// Who to fail, if what went wrong under the lock turns out to concern an ACTIVATION rather than
|
|
1471
|
+
// this branch's opportunistic cleanup. Left unset for a sweep that could not remove a settled
|
|
1472
|
+
// directory and for a lock a live deploy is holding: neither is an unsettled activation.
|
|
1473
|
+
let activationToFail;
|
|
1474
|
+
// Set when the journal that appears under the lock names someone other than the sidecar owner
|
|
1475
|
+
// whose lock we took. Both names are failed, exactly as on the journaled path.
|
|
1476
|
+
let splitOwners;
|
|
1477
|
+
const removeResidue = async () => {
|
|
1478
|
+
// Re-read UNDER the lock, and do not swallow: the first scan raced a deploy that can publish a
|
|
1479
|
+
// journal before releasing the lock, so a journal found now must be settled rather than deleted.
|
|
1480
|
+
// Treating a read error as "no journal" would delete the evidence instead.
|
|
1481
|
+
let appeared;
|
|
1482
|
+
try {
|
|
1483
|
+
appeared = await readActivationJournal((0, node_path_1.join)(deploymentDirPath, ACTIVATION_JOURNAL));
|
|
1484
|
+
}
|
|
1485
|
+
catch (error) {
|
|
1486
|
+
// A journal published between the scan's read and this one, which then cannot be READ, is an
|
|
1487
|
+
// activation whose intent is unknowable — the one thing in this branch that has to fail
|
|
1488
|
+
// closed. Attributed to the sidecar's owner, since the journal cannot name itself.
|
|
1489
|
+
activationToFail = owner ?? deployment.name;
|
|
1490
|
+
throw error;
|
|
1491
|
+
}
|
|
1492
|
+
if (appeared) {
|
|
1493
|
+
// The lock held here was taken on the SIDECAR's owner. A journal naming someone else must not
|
|
1494
|
+
// be settled under it: `settleInterruptedActivation` renames and removes that other
|
|
1495
|
+
// component's trees, whose own deploy may hold its own lock and be mid-flight. It is also the
|
|
1496
|
+
// same split evidence the journaled path fails closed for both names, so it takes the same
|
|
1497
|
+
// route rather than a second opinion here.
|
|
1498
|
+
const splitNames = splitAttributionOwners(appeared.component, owner);
|
|
1499
|
+
if (splitNames) {
|
|
1500
|
+
splitOwners = splitNames;
|
|
1501
|
+
throw splitAttributionError(deploymentDirPath, appeared.component, splitNames[0]);
|
|
1502
|
+
}
|
|
1503
|
+
activationToFail = appeared.component;
|
|
1504
|
+
await settleInterruptedActivation(componentsRootDirPath, deploymentDirPath, appeared);
|
|
1505
|
+
// Settled. Anything that fails after this — releasing the lock, say — is not this
|
|
1506
|
+
// activation's, and attributing it here would fail a correctly settled component closed.
|
|
1507
|
+
activationToFail = undefined;
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
// Cleanup, not settlement. There was no activation here — this is most often the residue a
|
|
1511
|
+
// SUCCESSFUL settlement leaves when its own sweep failed — so a sweep that fails again cannot
|
|
1512
|
+
// make anything unsettled, and recording it would refuse a live component on every worker
|
|
1513
|
+
// until the filesystem fault cleared.
|
|
1514
|
+
await (0, promises_1.rm)(deploymentDirPath, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }).catch((error) => harper_logger_ts_1.default.warn(`Could not clean up deploy staging ${deploymentDirPath}:`, (0, harper_logger_ts_1.errorForLog)(error)));
|
|
1515
|
+
};
|
|
1516
|
+
// Attribution FIRST, in its own scope, and its failure is not a verdict. A journal-less directory
|
|
1517
|
+
// is what a successful settlement leaves when its best-effort sweep fails, so a `fail()` here
|
|
1518
|
+
// wrote `.unsettled` keyed by the deployment id for a deployment that never held an unsettled
|
|
1519
|
+
// activation — and nothing ever cleared it, because settlement never runs for a journal-less
|
|
1520
|
+
// directory. If that sidecar later became readable as `web`, the stale marker was attributed to
|
|
1521
|
+
// the live `web` and every worker refused it permanently. This is the same shape the deploy path
|
|
1522
|
+
// skips; the two paths now agree.
|
|
1523
|
+
try {
|
|
1524
|
+
owner = await candidateComponentName(deploymentDirPath);
|
|
1525
|
+
}
|
|
1526
|
+
catch (error) {
|
|
1527
|
+
harper_logger_ts_1.default.trace?.(`Leaving deploy staging ${deploymentDirPath} in place: it holds no activation journal and its ` +
|
|
1528
|
+
`ownership cannot be read: ${errorMessage(error)}`);
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
// Scoped to THIS deployment, like the journaled branch below: a lock timeout or an EIO here used to
|
|
1532
|
+
// abort the entire scan, leaving every later deployment unsettled and unmarked.
|
|
1533
|
+
try {
|
|
1534
|
+
if (owner) {
|
|
1535
|
+
await (0, componentPreparationLock_ts_1.withComponentPreparationLock)((0, node_path_1.join)(componentsRootDirPath, owner), removeResidue, {
|
|
1536
|
+
purpose: 'activation-recovery',
|
|
1537
|
+
...RECOVERY_LOCK_WAIT,
|
|
1538
|
+
// Without this a ticket left by a CRASHED worker looks live — same pid, same process
|
|
1539
|
+
// instance — so recovery waits out the multi-hour default instead of reclaiming it.
|
|
1540
|
+
isOwnerAlive: (lockOwner) => lockOwner.pid !== process.pid || (0, manageThreads_js_1.isThreadRunning)(lockOwner.threadId),
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
// NOT removed. `buildCandidateApplication` creates the deployment directory and can then spend
|
|
1545
|
+
// minutes resolving or packing before the candidate tree and its sidecar exist, so "no owner"
|
|
1546
|
+
// includes "a live build that has not got that far yet" — and deleting it races the extraction
|
|
1547
|
+
// and fails a valid deploy. Unowned residue is left for a later pass, once an owner is knowable.
|
|
1548
|
+
harper_logger_ts_1.default.trace?.(`Leaving unowned deploy staging ${deploymentDirPath} in place: no component names it`);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
catch (error) {
|
|
1552
|
+
// A verdict only when an activation was actually involved; a directory that cannot be swept is
|
|
1553
|
+
// not one. A lock TIMEOUT is still recorded, because it is the signal `componentLoader` uses
|
|
1554
|
+
// to defer this component until the deploy holding that lock finishes — and it leaves nothing
|
|
1555
|
+
// durable behind, since `fail()` writes no marker for a deferral.
|
|
1556
|
+
if (splitOwners) {
|
|
1557
|
+
for (const name of splitOwners)
|
|
1558
|
+
await fail(name, error);
|
|
1559
|
+
}
|
|
1560
|
+
else if (activationToFail)
|
|
1561
|
+
await fail(activationToFail, error);
|
|
1562
|
+
else if (error instanceof componentPreparationLock_ts_1.ComponentPreparationLockTimeoutError)
|
|
1563
|
+
await fail(owner ?? deployment.name, error);
|
|
1564
|
+
else
|
|
1565
|
+
harper_logger_ts_1.default.warn(`Could not settle deploy staging ${deploymentDirPath}, which holds no activation journal:`, (0, harper_logger_ts_1.errorForLog)(error instanceof Error ? error : new Error(String(error))));
|
|
1566
|
+
}
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
try {
|
|
1570
|
+
// Disagreeing attributions are the one case with no automated way out: the restore gate blocks the
|
|
1571
|
+
// SIDECAR's component (it takes the union, because restoring is destructive) while settlement
|
|
1572
|
+
// keys the journal, so neither name's deploy could ever clear it. Reported as unsettleable
|
|
1573
|
+
// against the sidecar's name, which is the component actually stalled, instead of stalling it
|
|
1574
|
+
// silently on every boot.
|
|
1575
|
+
// Unreadable is not disagreement. The journal is the authority on this path — it named its
|
|
1576
|
+
// component and can settle it — so a sidecar that cannot be read must not block that; only one
|
|
1577
|
+
// that CAN be read and names something else is the wedge below.
|
|
1578
|
+
const sidecarOwner = await candidateComponentName(deploymentDirPath).catch(() => undefined);
|
|
1579
|
+
const splitNames = splitAttributionOwners(journal.component, sidecarOwner);
|
|
1580
|
+
if (splitNames) {
|
|
1581
|
+
const split = splitAttributionError(deploymentDirPath, journal.component, splitNames[0]);
|
|
1582
|
+
for (const name of splitNames)
|
|
1583
|
+
await fail(name, split);
|
|
1584
|
+
continue;
|
|
1585
|
+
}
|
|
1586
|
+
const settling = journal;
|
|
1587
|
+
await (0, componentPreparationLock_ts_1.withComponentPreparationLock)((0, node_path_1.join)(componentsRootDirPath, settling.component), () => settleInterruptedActivation(componentsRootDirPath, deploymentDirPath, settling), {
|
|
1588
|
+
purpose: 'activation-recovery',
|
|
1589
|
+
...RECOVERY_LOCK_WAIT,
|
|
1590
|
+
isOwnerAlive: (lockOwner) => lockOwner.pid !== process.pid || (0, manageThreads_js_1.isThreadRunning)(lockOwner.threadId),
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
catch (error) {
|
|
1594
|
+
// The journal named its component, so attribution is exact however the settle failed.
|
|
1595
|
+
await fail(journal.component, error);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return failures;
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Retire and sweep the rollback records a settled activation leaves. Retiring throws — it is what makes a
|
|
1602
|
+
* record non-authoritative, so a caller that removed the journal without it re-creates the inversion the
|
|
1603
|
+
* journal prevents. Sweeping the displaced tree only costs disk, so it is logged.
|
|
1604
|
+
*/
|
|
1605
|
+
async function sweepAsideRecords(records, componentName, liveDirPath, asideStagingDir) {
|
|
1606
|
+
for (const record of records) {
|
|
1607
|
+
// RETIRING IS CORRECTNESS, not hygiene: the retired marker is what stops the legacy pass treating this
|
|
1608
|
+
// record as authoritative and restoring the displaced tree over the candidate that was just rolled
|
|
1609
|
+
// forward, once the journal that would otherwise hold it back is gone. A record left un-retired while the journal is removed re-creates exactly
|
|
1610
|
+
// the inversion this protocol exists to prevent, so a failure here PROPAGATES — the caller keeps the
|
|
1611
|
+
// journal and the next start retries.
|
|
1612
|
+
const retiredMarkerPath = await retireExtractionAside(record);
|
|
1613
|
+
// Sweeping the displaced tree is hygiene: it bounds disk, and a failure costs space rather than
|
|
1614
|
+
// correctness, so it is logged. The retired marker above already makes the record non-authoritative.
|
|
1615
|
+
await cleanupExtractionPaths({ name: componentName, dirPath: liveDirPath, logger: harper_logger_ts_1.default }, asideStagingDir, new Set([record, retiredMarkerPath])).catch((error) => harper_logger_ts_1.default.warn(`Settled ${componentName} but could not sweep ${record}:`, (0, harper_logger_ts_1.errorForLog)(error)));
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* One interrupted activation, under the component preparation lock. Ambiguity exists only while the live
|
|
1620
|
+
* path is absent, and there the `complete` marker is the roll-forward authority: without it the candidate
|
|
1621
|
+
* was never validated, so the committed tree in the aside wins. Every branch is idempotent, so a crash
|
|
1622
|
+
* during recovery is settled by the next run.
|
|
1623
|
+
*/
|
|
1624
|
+
async function settleInterruptedActivation(componentsRootDirPath, deploymentDirPath, journal) {
|
|
1625
|
+
const liveDirPath = (0, node_path_1.join)(componentsRootDirPath, journal.component);
|
|
1626
|
+
const candidateDirPath = (0, node_path_1.join)(deploymentDirPath, journal.component);
|
|
1627
|
+
const asideStagingDir = extractionStagingDirectory(liveDirPath);
|
|
1628
|
+
const journalPath = (0, node_path_1.join)(deploymentDirPath, ACTIVATION_JOURNAL);
|
|
1629
|
+
const exists = async (path) => (0, promises_1.lstat)(path).then(() => true, (error) => {
|
|
1630
|
+
if (error.code === 'ENOENT')
|
|
1631
|
+
return false;
|
|
1632
|
+
throw error;
|
|
1633
|
+
});
|
|
1634
|
+
const liveExists = await exists(liveDirPath);
|
|
1635
|
+
const candidateExists = await exists(candidateDirPath);
|
|
1636
|
+
const candidateComplete = await exists((0, node_path_1.join)(deploymentDirPath, CANDIDATE_COMPLETE_MARKER));
|
|
1637
|
+
const asideRecords = await inProgressAsideRecords(asideStagingDir);
|
|
1638
|
+
const rollForward = async () => {
|
|
1639
|
+
if (!liveExists)
|
|
1640
|
+
await (0, promises_1.rename)(candidateDirPath, liveDirPath);
|
|
1641
|
+
// Unconditional, not only when THIS pass performed the rename: a crash after normal activation
|
|
1642
|
+
// renamed the candidate but before it repaired the links leaves live present with stale targets, and
|
|
1643
|
+
// gating the repair on the rename would skip exactly that case. Idempotent when there is nothing to
|
|
1644
|
+
// re-point.
|
|
1645
|
+
await repairRelocatedDependencyLinks(liveDirPath, candidateDirPath);
|
|
1646
|
+
await syncRenameParents(candidateDirPath, liveDirPath);
|
|
1647
|
+
// Retiring PROPAGATES from here: the retired marker is what stops the legacy pass restoring the tree
|
|
1648
|
+
// this roll-forward just displaced. Failing the component closed and retrying at the next start is
|
|
1649
|
+
// the cheaper mistake — the journal survives, so the verdict is re-derivable. Only the disk sweep
|
|
1650
|
+
// inside is best-effort.
|
|
1651
|
+
await sweepAsideRecords(asideRecords, journal.component, liveDirPath, asideStagingDir);
|
|
1652
|
+
};
|
|
1653
|
+
const rollBack = async (restoreFrom) => {
|
|
1654
|
+
if (restoreFrom) {
|
|
1655
|
+
await (0, promises_1.rename)(restoreFrom, liveDirPath);
|
|
1656
|
+
await syncRenameParents(restoreFrom, liveDirPath);
|
|
1657
|
+
}
|
|
1658
|
+
for (const record of asideRecords) {
|
|
1659
|
+
try {
|
|
1660
|
+
await (0, promises_1.rm)(record, { recursive: true, force: true });
|
|
1661
|
+
}
|
|
1662
|
+
catch (error) {
|
|
1663
|
+
// A record that survives removal is still AUTHORITATIVE to the legacy pass, and settlement is
|
|
1664
|
+
// about to remove the journal that holds that pass back — so it would restore this older tree
|
|
1665
|
+
// over the component just rolled back. Retiring is what makes a record non-authoritative, so
|
|
1666
|
+
// do that instead of logging and moving on. A retire that ALSO fails propagates: the journal
|
|
1667
|
+
// then survives and the next start retries, which is the same contract roll-forward uses.
|
|
1668
|
+
harper_logger_ts_1.default.warn(`Rolled ${journal.component} back but could not remove ${record}:`, (0, harper_logger_ts_1.errorForLog)(error));
|
|
1669
|
+
await retireExtractionAside(record);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
if (!liveExists) {
|
|
1674
|
+
if (candidateExists && candidateComplete) {
|
|
1675
|
+
await rollForward();
|
|
1676
|
+
}
|
|
1677
|
+
else {
|
|
1678
|
+
// The tree that was moved aside is the last committed one. A `-prior-absent` record means there
|
|
1679
|
+
// was nothing live to begin with, so rolling back means leaving the component absent.
|
|
1680
|
+
const restorable = asideRecords.find((record) => !record.endsWith(PRIOR_ABSENT_RECORD_SUFFIX));
|
|
1681
|
+
if (!restorable && !asideRecords.length) {
|
|
1682
|
+
throw new Error(`Cannot settle the interrupted activation of ${journal.component}: it has neither a live tree, ` +
|
|
1683
|
+
`a complete candidate, nor a rollback record, so no version of it can be recovered`);
|
|
1684
|
+
}
|
|
1685
|
+
await rollBack(restorable);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
else if (candidateExists) {
|
|
1689
|
+
// Live and candidate both present normally means B1 never ran: the swap had not started, so the live
|
|
1690
|
+
// tree stands and the candidate goes.
|
|
1691
|
+
//
|
|
1692
|
+
// Unless a rollback record says B1 DID run. Then the committed tree is the one in the aside, and
|
|
1693
|
+
// whatever sits at the live path was put there afterwards — a previous-version worker recreating its
|
|
1694
|
+
// own directory, the case the extraction path guards with `identifyRollbackPlaceholder`. Rolling back
|
|
1695
|
+
// there deletes the committed tree AND the validated candidate and leaves that stub serving, so this
|
|
1696
|
+
// fails closed instead: both trees stay on disk for an operator to choose between.
|
|
1697
|
+
// NOT conditioned on the candidate being complete. `rollBack()` below removes every aside record, and
|
|
1698
|
+
// with a record present that tree is the last committed one — so deleting it destroys the only
|
|
1699
|
+
// surviving copy of the previous release whether or not the candidate was ever validated. What
|
|
1700
|
+
// `.complete` decides is which tree we would prefer, not whether discarding the other is safe.
|
|
1701
|
+
const displaced = asideRecords.find((record) => !record.endsWith(PRIOR_ABSENT_RECORD_SUFFIX));
|
|
1702
|
+
if (displaced) {
|
|
1703
|
+
throw new Error(`Cannot settle the interrupted activation of ${journal.component}: its previous tree was moved to ` +
|
|
1704
|
+
`${displaced}, but ${liveDirPath} exists again — something recreated it after the deploy moved ` +
|
|
1705
|
+
`it aside, so which tree is current cannot be determined without losing one of them. Remove ` +
|
|
1706
|
+
`whichever of the two is not the release you want once you have determined which that is.`);
|
|
1707
|
+
}
|
|
1708
|
+
await rollBack();
|
|
1709
|
+
}
|
|
1710
|
+
else {
|
|
1711
|
+
// The candidate is already live; only the tail of the transaction was lost.
|
|
1712
|
+
await rollForward();
|
|
1713
|
+
}
|
|
1714
|
+
// The same ordering barrier normal activation uses, and for the same reason: the journal is the only
|
|
1715
|
+
// thing left telling the legacy pass not to restore an aside. Removing it while an
|
|
1716
|
+
// `.in-progress-*` record still names the displaced tree — because the retire or the sweep did not
|
|
1717
|
+
// reach storage — lets that pass put the old version back over the new one at the next start. Flush the
|
|
1718
|
+
// aside directory first, and leave the journal in place if that cannot be confirmed; recovery is
|
|
1719
|
+
// idempotent, so the next run settles it again.
|
|
1720
|
+
try {
|
|
1721
|
+
await syncDirectory(asideStagingDir);
|
|
1722
|
+
await syncDirectory((0, node_path_1.dirname)(asideStagingDir));
|
|
1723
|
+
}
|
|
1724
|
+
catch (error) {
|
|
1725
|
+
harper_logger_ts_1.default.warn(`Settled the interrupted activation of ${journal.component} but could not flush its rollback record; ` +
|
|
1726
|
+
`leaving the journal for the next start: ${errorMessage(error)}`);
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
// Best-effort, matching the activation path: the activation is settled by this point, so a transient
|
|
1730
|
+
// EBUSY removing staging must not throw out of the recovery pass and take the other components with it.
|
|
1731
|
+
// An earlier failed recovery may have left an unsettled marker here. Cleared BEFORE the journal and
|
|
1732
|
+
// treated as correctness: main would report this component settled and load it, while every worker read
|
|
1733
|
+
// the stale marker and failed it closed.
|
|
1734
|
+
try {
|
|
1735
|
+
await (0, promises_1.rm)((0, node_path_1.join)(deploymentDirPath, UNSETTLED_MARKER), { force: true });
|
|
1736
|
+
}
|
|
1737
|
+
catch (error) {
|
|
1738
|
+
// The tree decision is applied, but the marker still says otherwise and every worker reads it and
|
|
1739
|
+
// fails the component closed. Thrown rather than returned so MAIN reaches that same verdict instead
|
|
1740
|
+
// of reporting the component settled — a split where main serves what every worker refuses is worse
|
|
1741
|
+
// than both refusing. The journal survives, so the next start settles again.
|
|
1742
|
+
throw new Error(`Settled the interrupted activation of ${journal.component} but could not clear its unsettled ` +
|
|
1743
|
+
`marker at ${(0, node_path_1.join)(deploymentDirPath, UNSETTLED_MARKER)}; the component stays failed closed on ` +
|
|
1744
|
+
`every thread until that file can be removed: ${errorMessage(error)}`, { cause: error });
|
|
1745
|
+
}
|
|
1746
|
+
await (0, promises_1.rm)(journalPath, { force: true }).catch((error) => harper_logger_ts_1.default.warn(`Settled ${journal.component} but could not remove its activation journal:`, (0, harper_logger_ts_1.errorForLog)(error)));
|
|
1747
|
+
await (0, promises_1.rm)(deploymentDirPath, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }).catch((error) => harper_logger_ts_1.default.warn(`Settled ${journal.component} but could not clean up its staging directory:`, (0, harper_logger_ts_1.errorForLog)(error)));
|
|
1748
|
+
await (0, promises_1.rmdir)((0, node_path_1.dirname)(deploymentDirPath)).catch(() => { });
|
|
1749
|
+
}
|
|
1750
|
+
/** Mark a candidate build+validation complete. Idempotent, so a retried activation is not a failure. */
|
|
1751
|
+
/**
|
|
1752
|
+
* fsync the candidate's contents before `.complete` vouches for them — otherwise the control files can
|
|
1753
|
+
* outlive the tree after a power loss and recovery rolls forward onto a truncated one.
|
|
1754
|
+
*/
|
|
1755
|
+
// Codes that mean "this platform or filesystem will not fsync this handle", as opposed to "the write did
|
|
1756
|
+
// not reach storage". Windows raises EPERM fsyncing perfectly healthy files, and network/overlay mounts
|
|
1757
|
+
// return EINVAL or ENOTSUP — none of which say anything about durability, and all of which would otherwise
|
|
1758
|
+
// fail every deploy on those platforms.
|
|
1759
|
+
const UNSUPPORTED_SYNC_CODES = new Set(['EPERM', 'EINVAL', 'ENOTSUP', 'EOPNOTSUPP', 'EBADF', 'EISDIR']);
|
|
1760
|
+
function isUnsupportedSync(error) {
|
|
1761
|
+
return UNSUPPORTED_SYNC_CODES.has(error?.code ?? '');
|
|
1762
|
+
}
|
|
1763
|
+
// How many file syncs run at once while flushing a candidate. Serial open/sync/close over a large
|
|
1764
|
+
// dependency tree adds seconds to every activation, all of it under the component preparation lock; a small
|
|
1765
|
+
// fan-out keeps the ordering guarantee (everything is synced before `.complete` is written) without paying
|
|
1766
|
+
// per-file latency one file at a time.
|
|
1767
|
+
const CANDIDATE_SYNC_CONCURRENCY = 16;
|
|
1768
|
+
// Directories walked at once when re-pointing dependency links after a swap; a pnpm or monorepo tree is
|
|
1769
|
+
// thousands of directories and a serial depth-first walk after every activation is a real cost.
|
|
1770
|
+
const LINK_REPAIR_CONCURRENCY = 8;
|
|
1771
|
+
async function syncTreeContents(rootPath, foreignTree = false) {
|
|
1772
|
+
// Real durability failures propagate: the deploy fails, which is safe because the live tree is
|
|
1773
|
+
// untouched. Platform "cannot fsync this handle" codes do not — treating those as durability failures
|
|
1774
|
+
// fails every deploy on Windows.
|
|
1775
|
+
const entries = await (0, promises_1.readdir)(rootPath, { withFileTypes: true }).catch((error) => {
|
|
1776
|
+
// Same reasoning as the per-file tolerance below: a directory inside a foreign tree that this uid
|
|
1777
|
+
// cannot list is not ours to make durable, and failing here fails a deploy over a directory the
|
|
1778
|
+
// deploy never wrote.
|
|
1779
|
+
if (foreignTree && error?.code === 'EACCES') {
|
|
1780
|
+
harper_logger_ts_1.default.trace?.(`Sync of ${rootPath} unavailable: ${errorMessage(error)}`);
|
|
1781
|
+
return undefined;
|
|
1782
|
+
}
|
|
1783
|
+
throw error;
|
|
1784
|
+
});
|
|
1785
|
+
if (!entries)
|
|
1786
|
+
return;
|
|
1787
|
+
const syncFile = async (entryPath) => {
|
|
1788
|
+
let handle;
|
|
1789
|
+
try {
|
|
1790
|
+
handle = await (0, promises_1.open)(entryPath, 'r');
|
|
1791
|
+
}
|
|
1792
|
+
catch (error) {
|
|
1793
|
+
// `foreignTree`: a `file:<directory>` candidate is a symlink to a tree this deploy does not own,
|
|
1794
|
+
// so it can hold files the Harper uid cannot open. Those are not ours to make durable and their
|
|
1795
|
+
// EACCES says nothing about whether the install output beside them reached storage — while
|
|
1796
|
+
// failing here would fail an otherwise valid deploy over a file the deploy never touched. The
|
|
1797
|
+
// install output itself is written as this uid, so it is readable and still fsynced.
|
|
1798
|
+
//
|
|
1799
|
+
// The limit of that: this cannot tell a developer's unreadable source file from an install
|
|
1800
|
+
// script that deliberately made its OWN output unreadable, so `.complete` could certify output
|
|
1801
|
+
// that was never synced. Only for a `file:` candidate, and only for a script that chmods its
|
|
1802
|
+
// own artifacts away from the uid that has to run them.
|
|
1803
|
+
if (isUnsupportedSync(error) || (foreignTree && error?.code === 'EACCES')) {
|
|
1804
|
+
harper_logger_ts_1.default.trace?.(`Sync of ${entryPath} unavailable: ${errorMessage(error)}`);
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
throw error;
|
|
1808
|
+
}
|
|
1809
|
+
try {
|
|
1810
|
+
await handle.sync();
|
|
1811
|
+
}
|
|
1812
|
+
catch (error) {
|
|
1813
|
+
if (!isUnsupportedSync(error))
|
|
1814
|
+
throw error;
|
|
1815
|
+
harper_logger_ts_1.default.trace?.(`Sync of ${entryPath} unsupported: ${errorMessage(error)}`);
|
|
1816
|
+
}
|
|
1817
|
+
finally {
|
|
1818
|
+
await handle.close().catch(() => { });
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
const pending = [];
|
|
1822
|
+
for (const entry of entries) {
|
|
1823
|
+
const entryPath = (0, node_path_1.join)(rootPath, entry.name);
|
|
1824
|
+
if (entry.isDirectory()) {
|
|
1825
|
+
await syncTreeContents(entryPath, foreignTree);
|
|
1826
|
+
}
|
|
1827
|
+
else if (entry.isFile()) {
|
|
1828
|
+
pending.push(syncFile(entryPath));
|
|
1829
|
+
if (pending.length >= CANDIDATE_SYNC_CONCURRENCY) {
|
|
1830
|
+
await Promise.all(pending.splice(0));
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
await Promise.all(pending);
|
|
1835
|
+
await syncDirectory(rootPath);
|
|
1836
|
+
}
|
|
1837
|
+
async function markCandidateComplete(componentDirPath, deploymentId, componentName) {
|
|
1838
|
+
// Contents first: `.complete` is roll-forward AUTHORITY, so it must not be durable before the tree it
|
|
1839
|
+
// vouches for.
|
|
1840
|
+
//
|
|
1841
|
+
// A `file:<directory>` candidate IS a symlink to a tree this deploy does not own, but the dependency
|
|
1842
|
+
// install writes THROUGH it — so the tree still has to be walked, or the install output `.complete`
|
|
1843
|
+
// vouches for is never made durable. Only the foreign files alongside it are tolerated: see
|
|
1844
|
+
// `syncTreeContents`.
|
|
1845
|
+
const candidatePath = candidateApplicationPath(componentDirPath, deploymentId);
|
|
1846
|
+
const candidateIsLink = await (0, promises_1.lstat)(candidatePath).then((stats) => stats.isSymbolicLink(), (error) => {
|
|
1847
|
+
if (error.code === 'ENOENT')
|
|
1848
|
+
return false;
|
|
1849
|
+
throw error;
|
|
1850
|
+
});
|
|
1851
|
+
await syncTreeContents(candidatePath, candidateIsLink);
|
|
1852
|
+
try {
|
|
1853
|
+
await writeControlFileDurably(candidateComponentFilePath(componentDirPath, deploymentId), componentName);
|
|
1854
|
+
}
|
|
1855
|
+
catch (error) {
|
|
1856
|
+
if (error.code !== 'EEXIST')
|
|
1857
|
+
throw error;
|
|
1858
|
+
}
|
|
1859
|
+
try {
|
|
1860
|
+
await writeControlFileDurably(candidateCompleteMarkerPath(componentDirPath, deploymentId), '');
|
|
1861
|
+
}
|
|
1862
|
+
catch (error) {
|
|
1863
|
+
if (error.code !== 'EEXIST')
|
|
1864
|
+
throw error;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Make a built and validated candidate live, as one compensating transaction over two effects: the live tree
|
|
1869
|
+
* moves aside, then the candidate takes its place. Root config is NOT one of them — it is still published
|
|
1870
|
+
* before the build, unchanged, and making it transactional is tracked separately (#2315).
|
|
1871
|
+
*
|
|
1872
|
+
* The `complete` marker and the activation journal are written and fsynced BEFORE the first rename, so a
|
|
1873
|
+
* crash anywhere below is recoverable — see `settleInterruptedActivation` for the state matrix. The second
|
|
1874
|
+
* rename is the COMMIT POINT: nothing after it may compensate, because the live path holds the candidate and
|
|
1875
|
+
* renaming the aside back over it cannot succeed.
|
|
1876
|
+
*/
|
|
1877
|
+
async function activateCandidateApplication(application, deploymentId) {
|
|
1878
|
+
const liveDirPath = application.dirPath;
|
|
1879
|
+
const candidateDirPath = candidateApplicationPath(liveDirPath, deploymentId);
|
|
1880
|
+
const deploymentDirPath = candidateDeploymentDirPath(liveDirPath, deploymentId);
|
|
1881
|
+
const asideStagingDir = extractionStagingDirectory(liveDirPath);
|
|
1882
|
+
// A symlink counts: a `file:<directory>` deploy links the source rather than extracting it, and that
|
|
1883
|
+
// link is what gets swapped into the live path.
|
|
1884
|
+
const candidateStat = await (0, promises_1.lstat)(candidateDirPath).catch((error) => {
|
|
1885
|
+
if (error.code === 'ENOENT')
|
|
1886
|
+
return undefined;
|
|
1887
|
+
throw error;
|
|
1888
|
+
});
|
|
1889
|
+
if (!candidateStat || !(candidateStat.isDirectory() || candidateStat.isSymbolicLink())) {
|
|
1890
|
+
throw new Error(`Cannot activate ${application.name}: no candidate build at ${candidateDirPath}`);
|
|
1891
|
+
}
|
|
1892
|
+
await markCandidateComplete(liveDirPath, deploymentId, application.name);
|
|
1893
|
+
const journalPath = activationJournalPath(liveDirPath, deploymentId);
|
|
1894
|
+
try {
|
|
1895
|
+
await writeControlFileDurably(journalPath, JSON.stringify({
|
|
1896
|
+
v: ACTIVATION_JOURNAL_VERSION,
|
|
1897
|
+
component: application.name,
|
|
1898
|
+
candidateId: deploymentId,
|
|
1899
|
+
}));
|
|
1900
|
+
}
|
|
1901
|
+
catch (error) {
|
|
1902
|
+
// An existing journal is a retry of this same activation, not a conflict.
|
|
1903
|
+
if (error.code !== 'EEXIST')
|
|
1904
|
+
throw error;
|
|
1905
|
+
}
|
|
1906
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
1907
|
+
const liveExists = await (0, promises_1.lstat)(liveDirPath).then(() => true, (error) => {
|
|
1908
|
+
if (error.code === 'ENOENT')
|
|
1909
|
+
return false;
|
|
1910
|
+
throw error;
|
|
1911
|
+
});
|
|
1912
|
+
application.isNewComponent = !liveExists;
|
|
1913
|
+
// B1 — the live tree moves aside. It stays the rollback source until B4 retires it.
|
|
1914
|
+
let asidePath;
|
|
1915
|
+
let priorAbsentRecordPath;
|
|
1916
|
+
if (liveExists) {
|
|
1917
|
+
asidePath = (0, node_path_1.join)(asideStagingDir, `${IN_PROGRESS_ASIDE_PREFIX}${Date.now()}-${process.pid}-${(0, node_crypto_1.randomUUID)()}`);
|
|
1918
|
+
await (0, promises_1.rename)(liveDirPath, asidePath);
|
|
1919
|
+
}
|
|
1920
|
+
else {
|
|
1921
|
+
priorAbsentRecordPath = (0, node_path_1.join)(asideStagingDir, `${IN_PROGRESS_ASIDE_PREFIX}${Date.now()}-${process.pid}-${(0, node_crypto_1.randomUUID)()}${PRIOR_ABSENT_RECORD_SUFFIX}`);
|
|
1922
|
+
await (0, promises_1.writeFile)(priorAbsentRecordPath, '', { flag: 'wx', mode: 0o600 });
|
|
1923
|
+
}
|
|
1924
|
+
const restoreLive = async () => {
|
|
1925
|
+
if (asidePath)
|
|
1926
|
+
await (0, promises_1.rename)(asidePath, liveDirPath);
|
|
1927
|
+
else if (priorAbsentRecordPath)
|
|
1928
|
+
await (0, promises_1.rm)(priorAbsentRecordPath, { force: true });
|
|
1929
|
+
await syncRenameParents(asidePath ?? priorAbsentRecordPath, liveDirPath);
|
|
1930
|
+
};
|
|
1931
|
+
// Still BEFORE the commit point, so this is compensable — and must be compensated. Letting a storage
|
|
1932
|
+
// failure escape here leaves live already moved aside, and the caller reads an uncompensated throw as an
|
|
1933
|
+
// ordinary build failure and discards the candidate, its `.complete` marker and its journal: the
|
|
1934
|
+
// component ends up with no version at all and nothing saying how to get one back.
|
|
1935
|
+
try {
|
|
1936
|
+
await syncRenameParents(liveDirPath, asidePath ?? priorAbsentRecordPath);
|
|
1937
|
+
}
|
|
1938
|
+
catch (error) {
|
|
1939
|
+
await compensate(error, 'record the displaced component directory', restoreLive, application);
|
|
1940
|
+
throw error;
|
|
1941
|
+
}
|
|
1942
|
+
// B2 — the candidate becomes live. THE RENAME IS THE COMMIT POINT: nothing after it may compensate,
|
|
1943
|
+
// because the live path now holds the candidate and renaming the aside back over it cannot succeed. A
|
|
1944
|
+
// compensating step there fails its own rollback and reports a failure for a deploy that is live.
|
|
1945
|
+
try {
|
|
1946
|
+
await (0, promises_1.rename)(candidateDirPath, liveDirPath);
|
|
1947
|
+
}
|
|
1948
|
+
catch (error) {
|
|
1949
|
+
await compensate(error, 'move the candidate into place', restoreLive, application);
|
|
1950
|
+
throw error;
|
|
1951
|
+
}
|
|
1952
|
+
// Past the point of no return: each failure below leaves a state recovery settles forward, so they are
|
|
1953
|
+
// logged, not thrown.
|
|
1954
|
+
let swapDurable = true;
|
|
1955
|
+
try {
|
|
1956
|
+
await syncRenameParents(candidateDirPath, liveDirPath);
|
|
1957
|
+
}
|
|
1958
|
+
catch (error) {
|
|
1959
|
+
// The rename may not have reached storage. Retiring the record and removing the journal WOULD reach
|
|
1960
|
+
// it, and a power loss then leaves no live entry, no rollback record, and nothing saying to roll
|
|
1961
|
+
// forward. Both are skipped so the journal carries the activation to the next start.
|
|
1962
|
+
swapDurable = false;
|
|
1963
|
+
application.logger.warn(`Deployed ${application.name} but could not flush the swap to storage:`, error);
|
|
1964
|
+
}
|
|
1965
|
+
// The tree moved, so any dependency link that named its build path is now dangling.
|
|
1966
|
+
await repairRelocatedDependencyLinks(liveDirPath, candidateDirPath);
|
|
1967
|
+
const settledRecord = asidePath ?? priorAbsentRecordPath;
|
|
1968
|
+
let retired = false;
|
|
1969
|
+
// Skipped entirely when the swap is not known to be on storage, so the journal below survives.
|
|
1970
|
+
if (swapDurable) {
|
|
1971
|
+
try {
|
|
1972
|
+
const retiredMarkerPath = await retireExtractionAside(settledRecord);
|
|
1973
|
+
// Retiring only MARKS the displaced tree disposable. Without this sweep the tree every deploy
|
|
1974
|
+
// displaces stays under `.deploy-aside/<component>` forever, so the components root grows by a
|
|
1975
|
+
// whole component version per deploy.
|
|
1976
|
+
await cleanupExtractionPaths(application, asideStagingDir, new Set([settledRecord, retiredMarkerPath]));
|
|
1977
|
+
// Before the journal goes: if the journal's removal persists but the record's does not, startup sees
|
|
1978
|
+
// an in-progress aside with no journal and the legacy pass restores the old tree over the new one.
|
|
1979
|
+
await syncDirectory(asideStagingDir);
|
|
1980
|
+
await syncDirectory((0, node_path_1.dirname)(asideStagingDir));
|
|
1981
|
+
retired = true;
|
|
1982
|
+
}
|
|
1983
|
+
catch (error) {
|
|
1984
|
+
application.logger.warn(`Deployed ${application.name} but could not retire its rollback record:`, error);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
// The journal goes LAST, and only once the rollback record is settled: removing it while an
|
|
1988
|
+
// `.in-progress-*` record still names the displaced tree lets the legacy pass restore the old tree.
|
|
1989
|
+
if (retired) {
|
|
1990
|
+
await (0, promises_1.rm)(journalPath, { force: true }).catch((error) => application.logger.warn(`Deployed ${application.name} but could not remove its activation journal:`, error));
|
|
1991
|
+
await (0, promises_1.rm)(deploymentDirPath, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }).catch((error) => application.logger.warn(`Deployed ${application.name} but could not clean up its staging directory:`, error));
|
|
1992
|
+
await (0, promises_1.rmdir)((0, node_path_1.dirname)(deploymentDirPath)).catch(() => { });
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
/**
|
|
1996
|
+
* Marks a failure where compensation ITSELF failed, so the previous version is not back and the live path
|
|
1997
|
+
* may be absent. The candidate, its `.complete` marker and its journal are then the only way back — recovery
|
|
1998
|
+
* rolls that state forward — so they must survive, and the caller keys on this to skip discarding them.
|
|
1999
|
+
*/
|
|
2000
|
+
const COMPENSATION_INCOMPLETE = Symbol('compensationIncomplete');
|
|
2001
|
+
function compensationIncomplete(error) {
|
|
2002
|
+
return Boolean(error?.[COMPENSATION_INCOMPLETE]);
|
|
2003
|
+
}
|
|
2004
|
+
/**
|
|
2005
|
+
* Undo an activation effect, folding a compensation failure into the original error rather than replacing
|
|
2006
|
+
* it — the first error is what the operator needs, the second is why the node still needs attention.
|
|
2007
|
+
*/
|
|
2008
|
+
async function compensate(error, what, undo, application) {
|
|
2009
|
+
try {
|
|
2010
|
+
await undo();
|
|
2011
|
+
}
|
|
2012
|
+
catch (undoError) {
|
|
2013
|
+
// Whatever blocked the original operation plausibly blocks its undo too — a rename into a path
|
|
2014
|
+
// something else holds open fails the same way twice.
|
|
2015
|
+
const failure = new AggregateError([error, undoError], `Failed to ${what} for ${application.name}: ${errorMessage(error)}; ` +
|
|
2016
|
+
`also failed to restore the previous version: ${errorMessage(undoError)}`);
|
|
2017
|
+
failure[COMPENSATION_INCOMPLETE] = true;
|
|
2018
|
+
throw failure;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Re-point dependency links that name the candidate's build path, now that it has become live. npm links a
|
|
2023
|
+
* `file:` dependency relatively on POSIX (survives the rename) but as an ABSOLUTE junction on Windows, which
|
|
2024
|
+
* then names a staging path that no longer exists. Rewriting beats `--install-links`, which would change
|
|
2025
|
+
* dependency semantics on every platform to fix one.
|
|
2026
|
+
*/
|
|
2027
|
+
async function repairRelocatedDependencyLinks(liveDirPath, builtAtPath) {
|
|
2028
|
+
const relinkOne = async (entryPath) => {
|
|
2029
|
+
let target;
|
|
2030
|
+
try {
|
|
2031
|
+
target = await (0, promises_1.readlink)(entryPath);
|
|
2032
|
+
}
|
|
2033
|
+
catch {
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
const normalized = stripExtendedLengthPrefix(target);
|
|
2037
|
+
// Containment, not a prefix match: `startsWith` classifies `<build>-shared` as inside `<build>` and
|
|
2038
|
+
// would rewrite it to an unrelated live path.
|
|
2039
|
+
const within = (0, node_path_1.relative)(builtAtPath, normalized);
|
|
2040
|
+
if (within.startsWith('..') || (0, node_path_1.isAbsolute)(within))
|
|
2041
|
+
return;
|
|
2042
|
+
const repaired = (0, node_path_1.join)(liveDirPath, within);
|
|
2043
|
+
// The replacement is created BEFORE the old link is dropped, and swapped in by rename. A
|
|
2044
|
+
// remove-then-create loses the dependency outright when the create fails.
|
|
2045
|
+
const stagedLink = `${entryPath}.relink-${process.pid}-${(0, node_crypto_1.randomUUID)()}`;
|
|
2046
|
+
try {
|
|
2047
|
+
await (0, promises_1.symlink)(repaired, stagedLink, 'junction');
|
|
2048
|
+
try {
|
|
2049
|
+
await (0, promises_1.rename)(stagedLink, entryPath);
|
|
2050
|
+
}
|
|
2051
|
+
catch (renameError) {
|
|
2052
|
+
// Windows cannot rename over an existing junction, so the old one has to go first — and if the
|
|
2053
|
+
// second rename then fails the same way, the original target is put back rather than leaving
|
|
2054
|
+
// nothing behind.
|
|
2055
|
+
if (process.platform !== 'win32')
|
|
2056
|
+
throw renameError;
|
|
2057
|
+
await (0, promises_1.rm)(entryPath, { recursive: true, force: true });
|
|
2058
|
+
try {
|
|
2059
|
+
await (0, promises_1.rename)(stagedLink, entryPath);
|
|
2060
|
+
}
|
|
2061
|
+
catch (secondError) {
|
|
2062
|
+
await (0, promises_1.symlink)(normalized, entryPath, 'junction').catch(() => { });
|
|
2063
|
+
throw secondError;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
catch (error) {
|
|
2068
|
+
await (0, promises_1.rm)(stagedLink, { recursive: true, force: true }).catch(() => { });
|
|
2069
|
+
harper_logger_ts_1.default.warn(`Could not re-point ${entryPath} after activation: ${errorMessage(error)}`);
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
// ONE bounded pool over a shared queue, not per-directory concurrency: bounding each parent
|
|
2073
|
+
// independently let every one of N workers start N more, so a deep pnpm or monorepo tree fanned out to
|
|
2074
|
+
// thousands of simultaneous opens. An EMFILE there would surface as skipped subtrees and dangling links.
|
|
2075
|
+
const pending = [(0, node_path_1.join)(liveDirPath, 'node_modules')];
|
|
2076
|
+
let active = 0;
|
|
2077
|
+
const visit = async (dirPath) => {
|
|
2078
|
+
let entries;
|
|
2079
|
+
try {
|
|
2080
|
+
entries = await (0, promises_1.readdir)(dirPath, { withFileTypes: true });
|
|
2081
|
+
}
|
|
2082
|
+
catch (error) {
|
|
2083
|
+
// Not silent. A missing directory is ordinary — the tree has no `node_modules`, or an install
|
|
2084
|
+
// removed one — but an EACCES or EMFILE here means links under it were never examined, which is
|
|
2085
|
+
// exactly the state that leaves a component running against a dangling dependency.
|
|
2086
|
+
if (error?.code !== 'ENOENT') {
|
|
2087
|
+
harper_logger_ts_1.default.warn(`Could not scan ${dirPath} for links to re-point after activation:`, (0, harper_logger_ts_1.errorForLog)(error));
|
|
2088
|
+
}
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
// Every directory, not just `@scope` containers and nested `node_modules`: a dependency installed from
|
|
2092
|
+
// outside the tree can be linked from deeper in.
|
|
2093
|
+
for (const entry of entries) {
|
|
2094
|
+
const entryPath = (0, node_path_1.join)(dirPath, entry.name);
|
|
2095
|
+
if (entry.isSymbolicLink())
|
|
2096
|
+
await relinkOne(entryPath);
|
|
2097
|
+
else if (entry.isDirectory())
|
|
2098
|
+
pending.push(entryPath);
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
const worker = async () => {
|
|
2102
|
+
for (;;) {
|
|
2103
|
+
const next = pending.pop();
|
|
2104
|
+
if (next === undefined) {
|
|
2105
|
+
// Another worker may still be about to enqueue children, so only stop once nothing is in flight.
|
|
2106
|
+
if (active === 0)
|
|
543
2107
|
return;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
throw new Error(`File path specified in package identifier is not a file or directory: ${packagePath}`);
|
|
547
|
-
}
|
|
548
|
-
// If its a file, we assume it can be unzipped and extracted.
|
|
549
|
-
// We are using maybe-gunzip to handle both gzipped and non-gzipped tarballs
|
|
550
|
-
// And then we are happy to let the `tar-fs` library handle the extraction.
|
|
551
|
-
// Maybe worth adding some detection or at least some error handling if that step below fails.
|
|
552
|
-
tarballPath = packagePath;
|
|
553
|
-
tarball = (0, node_fs_1.createReadStream)(tarballPath);
|
|
2108
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2109
|
+
continue;
|
|
554
2110
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
throw err;
|
|
561
|
-
}
|
|
2111
|
+
active++;
|
|
2112
|
+
try {
|
|
2113
|
+
await visit(next);
|
|
562
2114
|
}
|
|
2115
|
+
finally {
|
|
2116
|
+
active--;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
await Promise.all(Array.from({ length: LINK_REPAIR_CONCURRENCY }, worker));
|
|
2121
|
+
}
|
|
2122
|
+
/** Windows junction targets come back with an extended-length `\\?\` prefix that plain paths never have. */
|
|
2123
|
+
function stripExtendedLengthPrefix(target) {
|
|
2124
|
+
return target.startsWith('\\\\?\\') ? target.slice(4) : target;
|
|
2125
|
+
}
|
|
2126
|
+
/** Remove a candidate's whole deployment directory, best-effort — it is never the last good copy. */
|
|
2127
|
+
async function discardCandidate(application, deploymentId) {
|
|
2128
|
+
const deploymentDirPath = candidateDeploymentDirPath(application.dirPath, deploymentId);
|
|
2129
|
+
await (0, promises_1.rm)(deploymentDirPath, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }).catch((error) => application.logger.warn(`Failed to remove the abandoned deploy candidate at ${deploymentDirPath}:`, error));
|
|
2130
|
+
// And the staging root itself once nothing is in it, so an idle install leaves the components root as
|
|
2131
|
+
// it found it. ENOTEMPTY just means a concurrent deploy still owns a candidate.
|
|
2132
|
+
await (0, promises_1.rmdir)((0, node_path_1.dirname)(deploymentDirPath)).catch(() => { });
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Build a deploy candidate at `.deploy-staging/<deploymentId>/<component>`, leaving the live tree
|
|
2136
|
+
* completely untouched — this is what lets the previous version keep serving through the clone, the
|
|
2137
|
+
* extraction and the dependency install.
|
|
2138
|
+
*
|
|
2139
|
+
* Failure needs no compensation, which is the whole point: nothing about the live component was modified,
|
|
2140
|
+
* so the abandoned candidate is simply removed and the error propagates.
|
|
2141
|
+
*/
|
|
2142
|
+
async function buildCandidateApplication(application, deploymentId) {
|
|
2143
|
+
const deploymentDirPath = candidateDeploymentDirPath(application.dirPath, deploymentId);
|
|
2144
|
+
const candidateDirPath = candidateApplicationPath(application.dirPath, deploymentId);
|
|
2145
|
+
await ensureSecureStagingDirectory((0, node_path_1.dirname)(deploymentDirPath));
|
|
2146
|
+
await ensureSecureStagingDirectory(deploymentDirPath);
|
|
2147
|
+
try {
|
|
2148
|
+
// Replaced, not extracted into: a prior attempt on this id may have left a partial tree.
|
|
2149
|
+
await (0, promises_1.rm)(candidateDirPath, { recursive: true, force: true });
|
|
2150
|
+
const resolved = await resolveApplicationTarball(application);
|
|
2151
|
+
if (resolved.kind === 'link') {
|
|
2152
|
+
// A `file:` directory becomes a symlink AT THE CANDIDATE PATH, so it is validated and swapped in
|
|
2153
|
+
// like any other candidate instead of appearing at the live path unvalidated.
|
|
2154
|
+
await (0, promises_1.symlink)(resolved.sourceDirPath, candidateDirPath, 'dir');
|
|
563
2155
|
}
|
|
564
2156
|
else {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
//
|
|
569
|
-
// Packing a git reference is not just a download: npm clones the repo and, if its manifest
|
|
570
|
-
// has a prepare/build/install script, runs `npm install` inside the clone and then that
|
|
571
|
-
// script — so the repository's (and its dependencies') install scripts can execute on this
|
|
572
|
-
// node during the pack step alone, independent of the later `npm install`.
|
|
573
|
-
// `install_allow_scripts` is the operator-facing switch for whether component code is
|
|
574
|
-
// allowed to run scripts on this node at all — with a credential session live, an
|
|
575
|
-
// unreviewed script also reaching the socket (a transitive dependency's postinstall asking
|
|
576
|
-
// for a token granted to the top-level repository) is exactly the reach the credential must
|
|
577
|
-
// not have, so this gates the pack step regardless of whether a credential happens to be in
|
|
578
|
-
// play.
|
|
579
|
-
const allowScripts = !!application.install?.allowInstallScripts;
|
|
580
|
-
if (allowScripts)
|
|
581
|
-
application.installationIsOpaque = true;
|
|
582
|
-
// `--ignore-scripts` alone isn't a reliable way to enforce that: pacote's DirFetcher runs a
|
|
583
|
-
// git source's `prepare` unconditionally on npm versions before 11.0.0 (see
|
|
584
|
-
// packGitReferenceWithoutScripts), which is exactly what Node 22's bundled npm ships. For a
|
|
585
|
-
// recognized git-reference identifier, clone and pack it ourselves with scripts stripped
|
|
586
|
-
// instead, sidestepping that npm code path entirely.
|
|
587
|
-
const gitRef = allowScripts ? null : parseGitReference(application.packageIdentifier);
|
|
588
|
-
if (!allowScripts && !gitRef && looksLikeGitReference(application.packageIdentifier)) {
|
|
589
|
-
// Recognized as git, but a form the reclone-and-strip-scripts path above can't safely
|
|
590
|
-
// handle (a `#path:` committish, or a hosted shorthand other than a plain `owner/repo`) —
|
|
591
|
-
// fail loudly rather than silently falling through to the unreliable `npm pack
|
|
592
|
-
// --ignore-scripts` below.
|
|
593
|
-
throw new Error(`Cannot deploy git-reference package '${application.packageIdentifier}' with install scripts disallowed: this identifier's form (e.g. a '#path:' committish, or a hosted shorthand other than a plain 'owner/repo') isn't one this repo's script-suppression handling supports. Set install.allowInstallScripts to true, or use a plain git URL with a branch/tag/commit committish instead.`);
|
|
594
|
-
}
|
|
595
|
-
if (gitRef) {
|
|
596
|
-
tarballPath = await packGitReferenceWithoutScripts(application, gitRef, parentDirPath);
|
|
2157
|
+
const { tarball, tarballPath, shouldDeleteTarball } = resolved;
|
|
2158
|
+
try {
|
|
2159
|
+
await extractTarballInto(tarball, candidateDirPath, deploymentDirPath);
|
|
597
2160
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
else if (application.gitCredentialEnv) {
|
|
604
|
-
application.logger.warn(`Deploying ${application.name} from a git reference with install scripts enabled: the repository's ` +
|
|
605
|
-
`prepare/build scripts and its dependencies' install scripts run on this node during the clone and ` +
|
|
606
|
-
`can read the git credential. Unset install_allow_scripts to keep the credential out of their reach.`);
|
|
2161
|
+
finally {
|
|
2162
|
+
if (!tarball.destroyed)
|
|
2163
|
+
tarball.destroy();
|
|
2164
|
+
if (shouldDeleteTarball && tarballPath) {
|
|
2165
|
+
await (0, promises_1.rm)(tarballPath, { force: true }).catch((error) => application.logger.warn(`Failed to remove temporary package ${tarballPath}:`, error));
|
|
607
2166
|
}
|
|
608
|
-
tarballPath = await runNpmPack(application, packArgs, parentDirPath, application.gitCredentialEnv);
|
|
609
2167
|
}
|
|
610
|
-
shouldDeleteTarball = true;
|
|
611
|
-
tarball = (0, node_fs_1.createReadStream)(tarballPath);
|
|
612
2168
|
}
|
|
2169
|
+
// The credential socket only has to be up for extraction — that is where npm resolves and clones a
|
|
2170
|
+
// git-reference package. Closed BEFORE the install so the dependency tree's own install scripts,
|
|
2171
|
+
// which are arbitrary code from the registry running as this uid, cannot ask the helper for the
|
|
2172
|
+
// deployer's git token. `prepareApplication`'s finally still calls this; it is idempotent.
|
|
2173
|
+
await application.cleanupGitCredentialSession();
|
|
2174
|
+
await installApplication(application, candidateDirPath);
|
|
2175
|
+
return candidateDirPath;
|
|
613
2176
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
// an in-place recursive rm races that writer: rm empties `.next`, then its leaf
|
|
618
|
-
// `rmdir('.next')` fails with ENOTEMPTY because the worker just re-created a cache
|
|
619
|
-
// entry. (`force: true` only suppresses ENOENT; ENOTEMPTY is not retried unless
|
|
620
|
-
// `maxRetries` is set, and a continuously-writing app would outlast retries
|
|
621
|
-
// anyway.) Renaming the old directory aside is atomic and immune to the race: the
|
|
622
|
-
// still-running worker keeps writing into the renamed inode harmlessly until it's
|
|
623
|
-
// replaced on restart, and the aside copy is removed best-effort below.
|
|
624
|
-
//
|
|
625
|
-
// The aside lives under a hidden, component-scoped staging directory inside the
|
|
626
|
-
// components root: same filesystem as the source so the rename stays atomic, the
|
|
627
|
-
// leading dot keeps loadComponentDirectories from picking it up as a phantom
|
|
628
|
-
// component, and the per-component path means a sibling component never collides
|
|
629
|
-
// with (or sweeps) another's aside.
|
|
630
|
-
const asideStagingDir = (0, node_path_1.join)((0, node_path_1.dirname)(application.dirPath), exports.ASIDE_STAGING_DIR, (0, node_path_1.basename)(application.dirPath));
|
|
631
|
-
let asidePath;
|
|
632
|
-
try {
|
|
633
|
-
await (0, promises_1.access)(application.dirPath, promises_1.constants.F_OK);
|
|
634
|
-
await (0, promises_1.mkdir)(asideStagingDir, { recursive: true });
|
|
635
|
-
const candidateAsidePath = (0, node_path_1.join)(asideStagingDir, `${process.pid}-${Date.now()}-${(0, node_crypto_1.randomUUID)()}`);
|
|
636
|
-
await (0, promises_1.rename)(application.dirPath, candidateAsidePath);
|
|
637
|
-
asidePath = candidateAsidePath;
|
|
2177
|
+
catch (error) {
|
|
2178
|
+
await discardCandidate(application, deploymentId);
|
|
2179
|
+
throw error;
|
|
638
2180
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
2181
|
+
}
|
|
2182
|
+
async function recoverOrCleanupStaleExtractionPaths(application, asideStagingDir) {
|
|
2183
|
+
const entries = await (0, promises_1.readdir)(asideStagingDir, { withFileTypes: true });
|
|
2184
|
+
const entryNames = new Set(entries.map((entry) => entry.name));
|
|
2185
|
+
const paths = new Set(entries.map((entry) => (0, node_path_1.join)(asideStagingDir, entry.name)));
|
|
2186
|
+
const recoveryRecords = entries
|
|
2187
|
+
.filter((entry) => isExtractionRecoveryRecord(entry) &&
|
|
2188
|
+
entry.name.startsWith(IN_PROGRESS_ASIDE_PREFIX) &&
|
|
2189
|
+
!entryNames.has(`${RETIRED_ASIDE_PREFIX}${entry.name.slice(IN_PROGRESS_ASIDE_PREFIX.length)}`))
|
|
2190
|
+
.map((entry) => ({
|
|
2191
|
+
entry,
|
|
2192
|
+
priorStateAbsent: isPriorAbsentRecoveryRecord(entry),
|
|
2193
|
+
timestamp: extractionAsideTimestamp(entry.name),
|
|
2194
|
+
}))
|
|
2195
|
+
.filter(({ timestamp }) => Number.isFinite(timestamp))
|
|
2196
|
+
.sort((left, right) => right.timestamp - left.timestamp);
|
|
2197
|
+
const recoveryRecord = recoveryRecords.find(({ priorStateAbsent }) => !priorStateAbsent) ??
|
|
2198
|
+
recoveryRecords.find(({ priorStateAbsent }) => priorStateAbsent);
|
|
2199
|
+
if (recoveryRecord) {
|
|
2200
|
+
// A journal outranks the record. Without this the pass restores the tree a completed activation
|
|
2201
|
+
// displaced, back over the candidate it committed — the inversion the journal exists to prevent, and
|
|
2202
|
+
// reachable on any thread whose settlement did not run or did not succeed. Enforced HERE, at the one
|
|
2203
|
+
// place a tree is restored, so every entry point is covered by construction rather than by each
|
|
2204
|
+
// caller remembering to settle first — and so a component with nothing left to restore still loads.
|
|
2205
|
+
const journaled = await journaledDeploymentForComponent((0, node_path_1.dirname)(application.dirPath), application.name);
|
|
2206
|
+
if (journaled) {
|
|
2207
|
+
throw new Error(`Refusing to restore ${application.name} from ${recoveryRecord.entry.name}: the interrupted ` +
|
|
2208
|
+
`activation in ${journaled} is not settled, and its journal is the only record of which tree ` +
|
|
2209
|
+
`is current. If that journal names no component at all it cannot settle itself; remove that ` +
|
|
2210
|
+
`directory once you have determined which tree is current.`);
|
|
2211
|
+
}
|
|
2212
|
+
const recoveryPath = (0, node_path_1.join)(asideStagingDir, recoveryRecord.entry.name);
|
|
2213
|
+
// Retire the losing candidates durably; a cleanup that fails must not let a later
|
|
2214
|
+
// pass adopt one of them and restore an older tree over the one recovered here.
|
|
2215
|
+
for (const { entry } of recoveryRecords) {
|
|
2216
|
+
if (entry === recoveryRecord.entry)
|
|
2217
|
+
continue;
|
|
2218
|
+
paths.add(await retireExtractionAside((0, node_path_1.join)(asideStagingDir, entry.name)));
|
|
643
2219
|
}
|
|
2220
|
+
await rollbackExtractedDirectory(application, asideStagingDir, recoveryRecord.priorStateAbsent ? undefined : recoveryPath, paths, false);
|
|
2221
|
+
application.logger.warn((recoveryRecord.priorStateAbsent
|
|
2222
|
+
? `Removed the partial ${application.name} component directory after an interrupted first deploy`
|
|
2223
|
+
: `Recovered the previous ${application.name} component directory after an interrupted deploy`) +
|
|
2224
|
+
(recoveryRecords.length > 1 ? `; discarded ${recoveryRecords.length - 1} older recovery candidates` : ''));
|
|
2225
|
+
return;
|
|
644
2226
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
2227
|
+
await cleanupExtractionPaths(application, asideStagingDir, paths);
|
|
2228
|
+
}
|
|
2229
|
+
function isPriorAbsentRecoveryRecord(entry) {
|
|
2230
|
+
return entry.isFile() && entry.name.endsWith(PRIOR_ABSENT_RECORD_SUFFIX);
|
|
2231
|
+
}
|
|
2232
|
+
function isExtractionRecoveryRecord(entry) {
|
|
2233
|
+
return entry.isDirectory() || entry.isSymbolicLink() || isPriorAbsentRecoveryRecord(entry);
|
|
2234
|
+
}
|
|
2235
|
+
function extractionAsideTimestamp(name) {
|
|
2236
|
+
const timestampEnd = name.indexOf('-', IN_PROGRESS_ASIDE_PREFIX.length);
|
|
2237
|
+
if (timestampEnd < 0)
|
|
2238
|
+
return Number.NaN;
|
|
2239
|
+
return Number(name.slice(IN_PROGRESS_ASIDE_PREFIX.length, timestampEnd));
|
|
2240
|
+
}
|
|
2241
|
+
async function recoverInterruptedComponentExtractions(componentsRootDirPath) {
|
|
2242
|
+
const stagingRoot = (0, node_path_1.join)(componentsRootDirPath, exports.ASIDE_STAGING_DIR);
|
|
2243
|
+
let entries;
|
|
649
2244
|
try {
|
|
650
|
-
await (0, promises_1.
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if (extracted.length === 1 && extracted[0].isDirectory()) {
|
|
654
|
-
const topLevelDirPath = (0, node_path_1.join)(application.dirPath, extracted[0].name);
|
|
655
|
-
await (0, promises_1.mkdir)(asideStagingDir, { recursive: true });
|
|
656
|
-
const tempDirPath = await (0, promises_1.mkdtemp)((0, node_path_1.join)(asideStagingDir, '.normalize-'));
|
|
657
|
-
await (0, promises_1.cp)(topLevelDirPath, tempDirPath, { recursive: true });
|
|
658
|
-
await (0, promises_1.rm)(topLevelDirPath, { recursive: true, force: true });
|
|
659
|
-
await (0, promises_1.cp)(tempDirPath, application.dirPath, { recursive: true });
|
|
660
|
-
await (0, promises_1.rm)(tempDirPath, { recursive: true, force: true });
|
|
2245
|
+
const stagingStat = await (0, promises_1.lstat)(stagingRoot);
|
|
2246
|
+
if (!stagingStat.isDirectory() || stagingStat.isSymbolicLink()) {
|
|
2247
|
+
throw new Error(`Component deploy staging path is not a directory: ${stagingRoot}`);
|
|
661
2248
|
}
|
|
2249
|
+
entries = await (0, promises_1.readdir)(stagingRoot, { withFileTypes: true });
|
|
662
2250
|
}
|
|
663
2251
|
catch (error) {
|
|
2252
|
+
if (error.code === 'ENOENT')
|
|
2253
|
+
return new Map();
|
|
2254
|
+
throw error;
|
|
2255
|
+
}
|
|
2256
|
+
const failedComponents = new Map();
|
|
2257
|
+
await Promise.all(entries
|
|
2258
|
+
.filter((entry) => entry.isDirectory())
|
|
2259
|
+
.map(async (entry) => {
|
|
664
2260
|
try {
|
|
665
|
-
await
|
|
2261
|
+
await recoverInterruptedComponentExtraction(componentsRootDirPath, entry.name, false);
|
|
666
2262
|
}
|
|
667
|
-
catch (
|
|
668
|
-
|
|
2263
|
+
catch (error) {
|
|
2264
|
+
const recoveryError = error instanceof Error ? error : new Error(String(error));
|
|
2265
|
+
failedComponents.set(entry.name, recoveryError);
|
|
2266
|
+
const deferred = recoveryError instanceof componentPreparationLock_ts_1.ComponentPreparationLockTimeoutError;
|
|
2267
|
+
harper_logger_ts_1.default[deferred ? 'warn' : 'error'](`${deferred ? 'Deferring' : 'Not loading'} ${entry.name} because its interrupted component deployment ` +
|
|
2268
|
+
`${deferred ? 'is still being prepared' : 'could not be recovered'}:`, (0, harper_logger_ts_1.errorForLog)(recoveryError));
|
|
2269
|
+
}
|
|
2270
|
+
}));
|
|
2271
|
+
return failedComponents;
|
|
2272
|
+
}
|
|
2273
|
+
async function recoverInterruptedComponentExtraction(componentsRootDirPath, componentName, waitForPreparation = true, waitTimeoutMs = COMPONENT_RECOVERY_WAIT_TIMEOUT_MS) {
|
|
2274
|
+
const componentDirPath = (0, node_path_1.join)(componentsRootDirPath, componentName);
|
|
2275
|
+
await (0, componentPreparationLock_ts_1.withComponentPreparationLock)(componentDirPath, async () => {
|
|
2276
|
+
const asideStagingDir = extractionStagingDirectory(componentDirPath);
|
|
2277
|
+
try {
|
|
2278
|
+
await (0, promises_1.lstat)(asideStagingDir);
|
|
2279
|
+
}
|
|
2280
|
+
catch (error) {
|
|
2281
|
+
if (error.code === 'ENOENT')
|
|
2282
|
+
return;
|
|
2283
|
+
throw error;
|
|
669
2284
|
}
|
|
2285
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
2286
|
+
await recoverOrCleanupStaleExtractionPaths({ name: componentName, dirPath: componentDirPath, logger: harper_logger_ts_1.default }, asideStagingDir);
|
|
2287
|
+
}, {
|
|
2288
|
+
timeoutMs: waitForPreparation ? waitTimeoutMs : COMPONENT_RECOVERY_TRY_TIMEOUT_MS,
|
|
2289
|
+
purpose: COMPONENT_RECOVERY_LOCK_PURPOSE,
|
|
2290
|
+
renewTimeoutWhileOwnerAlive: waitForPreparation,
|
|
2291
|
+
onWait: (owner) => {
|
|
2292
|
+
harper_logger_ts_1.default.info(`Waiting to settle component deployment state for ${componentName}` +
|
|
2293
|
+
(owner ? ` held by process ${owner.pid}, thread ${owner.threadId}` : ''));
|
|
2294
|
+
},
|
|
2295
|
+
isOwnerAlive: (owner) => owner.pid !== process.pid || (0, manageThreads_js_1.isThreadRunning)(owner.threadId),
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
async function retireComponentExtractionStaging(componentDirPath, componentName = (0, node_path_1.basename)(componentDirPath), componentLogger = harper_logger_ts_1.default) {
|
|
2299
|
+
const asideStagingDir = extractionStagingDirectory(componentDirPath);
|
|
2300
|
+
let entries;
|
|
2301
|
+
try {
|
|
2302
|
+
await (0, promises_1.lstat)(asideStagingDir);
|
|
2303
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
2304
|
+
entries = await (0, promises_1.readdir)(asideStagingDir, { withFileTypes: true });
|
|
2305
|
+
}
|
|
2306
|
+
catch (error) {
|
|
2307
|
+
if (error.code === 'ENOENT')
|
|
2308
|
+
return;
|
|
670
2309
|
throw error;
|
|
671
2310
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
2311
|
+
const paths = new Set(entries.map((entry) => (0, node_path_1.join)(asideStagingDir, entry.name)));
|
|
2312
|
+
for (const entry of entries) {
|
|
2313
|
+
if (!isExtractionRecoveryRecord(entry) || !entry.name.startsWith(IN_PROGRESS_ASIDE_PREFIX))
|
|
2314
|
+
continue;
|
|
2315
|
+
const markerPath = retiredMarkerForAside((0, node_path_1.join)(asideStagingDir, entry.name));
|
|
2316
|
+
try {
|
|
2317
|
+
await (0, promises_1.writeFile)(markerPath, '', { flag: 'wx', mode: 0o600 });
|
|
2318
|
+
}
|
|
2319
|
+
catch (error) {
|
|
2320
|
+
if (error.code !== 'EEXIST')
|
|
2321
|
+
throw error;
|
|
2322
|
+
}
|
|
2323
|
+
paths.add(markerPath);
|
|
675
2324
|
}
|
|
676
|
-
|
|
677
|
-
// in the just-renamed copy (the live writer that motivated the rename), so this is
|
|
678
|
-
// best-effort: removing the whole staging subdirectory also clears leftovers from
|
|
679
|
-
// earlier deploys whose workers have since exited, and a copy that survives because
|
|
680
|
-
// its worker is still live is swept by the next deploy. The failure is expected in
|
|
681
|
-
// the live-worker case, so it's logged at trace rather than as a warning.
|
|
682
|
-
let settled = false;
|
|
683
|
-
const transaction = {
|
|
684
|
-
async commit() {
|
|
685
|
-
if (settled)
|
|
686
|
-
return;
|
|
687
|
-
settled = true;
|
|
688
|
-
await cleanupExtractionStaging(application, asideStagingDir);
|
|
689
|
-
},
|
|
690
|
-
async rollback() {
|
|
691
|
-
if (settled)
|
|
692
|
-
return;
|
|
693
|
-
settled = true;
|
|
694
|
-
await rollbackExtractedDirectory(application, asideStagingDir, asidePath);
|
|
695
|
-
},
|
|
696
|
-
};
|
|
697
|
-
if (deferCommit)
|
|
698
|
-
return transaction;
|
|
699
|
-
await transaction.commit();
|
|
2325
|
+
await cleanupExtractionPaths({ name: componentName, dirPath: componentDirPath, logger: componentLogger }, asideStagingDir, paths);
|
|
700
2326
|
}
|
|
701
|
-
async function
|
|
2327
|
+
async function dropComponentDirectory(componentDirPath, componentName = (0, node_path_1.basename)(componentDirPath), componentLogger = harper_logger_ts_1.default) {
|
|
2328
|
+
await retireComponentExtractionStaging(componentDirPath, componentName, componentLogger);
|
|
2329
|
+
const asideStagingDir = extractionStagingDirectory(componentDirPath);
|
|
2330
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
2331
|
+
const droppedPath = (0, node_path_1.join)(asideStagingDir, `.dropped-${process.pid}-${Date.now()}-${(0, node_crypto_1.randomUUID)()}`);
|
|
702
2332
|
try {
|
|
703
|
-
await (0, promises_1.
|
|
2333
|
+
await (0, promises_1.rename)(componentDirPath, droppedPath);
|
|
704
2334
|
}
|
|
705
2335
|
catch (error) {
|
|
706
|
-
|
|
2336
|
+
if (error.code !== 'ENOENT')
|
|
2337
|
+
throw error;
|
|
707
2338
|
}
|
|
2339
|
+
await cleanupExtractionPaths({ name: componentName, dirPath: componentDirPath, logger: componentLogger }, asideStagingDir, new Set([droppedPath]));
|
|
708
2340
|
}
|
|
709
|
-
async function
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
2341
|
+
async function cleanupExtractionPaths(application, asideStagingDir, paths) {
|
|
2342
|
+
const retiredMarkers = [];
|
|
2343
|
+
for (const path of paths) {
|
|
2344
|
+
if ((0, node_path_1.basename)(path).startsWith(RETIRED_ASIDE_PREFIX)) {
|
|
2345
|
+
retiredMarkers.push(path);
|
|
2346
|
+
continue;
|
|
2347
|
+
}
|
|
2348
|
+
try {
|
|
2349
|
+
await (0, promises_1.rm)(path, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
2350
|
+
}
|
|
2351
|
+
catch (error) {
|
|
2352
|
+
application.logger.trace?.(`Cleanup of previous ${application.name} component directory deferred: ${errorMessage(error)}`);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
for (const markerPath of retiredMarkers) {
|
|
2356
|
+
const asidePath = (0, node_path_1.join)(asideStagingDir, `${IN_PROGRESS_ASIDE_PREFIX}${(0, node_path_1.basename)(markerPath).slice(RETIRED_ASIDE_PREFIX.length)}`);
|
|
2357
|
+
try {
|
|
2358
|
+
await (0, promises_1.access)(asidePath, promises_1.constants.F_OK);
|
|
2359
|
+
continue;
|
|
2360
|
+
}
|
|
2361
|
+
catch (error) {
|
|
2362
|
+
if (error.code !== 'ENOENT')
|
|
2363
|
+
continue;
|
|
2364
|
+
}
|
|
2365
|
+
await (0, promises_1.rm)(markerPath, { force: true }).catch((error) => application.logger.trace?.(`Cleanup of previous ${application.name} component directory deferred: ${errorMessage(error)}`));
|
|
2366
|
+
}
|
|
2367
|
+
await (0, promises_1.rmdir)(asideStagingDir).catch((error) => {
|
|
2368
|
+
if (!['ENOENT', 'ENOTEMPTY'].includes(error.code ?? '')) {
|
|
2369
|
+
application.logger.trace?.(`Cleanup of ${application.name} deploy staging directory deferred: ${errorMessage(error)}`);
|
|
2370
|
+
}
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
async function rollbackExtractedDirectory(application, asideStagingDir, asidePath, transactionPaths, retainReplacement) {
|
|
2374
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
2375
|
+
const retryableRenameCodes = new Set(['EEXIST', 'ENOTEMPTY', 'ENOTDIR', 'EISDIR', 'EPERM', 'EACCES', 'EBUSY']);
|
|
2376
|
+
const displaceCurrentDirectorySync = () => {
|
|
713
2377
|
const displacedPath = (0, node_path_1.join)(asideStagingDir, `.failed-${process.pid}-${Date.now()}-${(0, node_crypto_1.randomUUID)()}`);
|
|
2378
|
+
try {
|
|
2379
|
+
(0, node_fs_1.renameSync)(application.dirPath, displacedPath);
|
|
2380
|
+
transactionPaths.add(displacedPath);
|
|
2381
|
+
return displacedPath;
|
|
2382
|
+
}
|
|
2383
|
+
catch (error) {
|
|
2384
|
+
if (error.code === 'ENOENT')
|
|
2385
|
+
return undefined;
|
|
2386
|
+
throw error;
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
const displaceCurrentDirectory = async () => {
|
|
2390
|
+
const retryDeadline = Date.now() + 5000;
|
|
714
2391
|
let lastError;
|
|
715
|
-
|
|
2392
|
+
do {
|
|
2393
|
+
const displacedPath = (0, node_path_1.join)(asideStagingDir, `.failed-${process.pid}-${Date.now()}-${(0, node_crypto_1.randomUUID)()}`);
|
|
716
2394
|
try {
|
|
717
2395
|
await (0, promises_1.rename)(application.dirPath, displacedPath);
|
|
718
|
-
|
|
2396
|
+
transactionPaths.add(displacedPath);
|
|
2397
|
+
return displacedPath;
|
|
719
2398
|
}
|
|
720
2399
|
catch (error) {
|
|
721
2400
|
const code = error.code;
|
|
722
2401
|
if (code === 'ENOENT')
|
|
723
|
-
return;
|
|
2402
|
+
return undefined;
|
|
724
2403
|
if (!retryableRenameCodes.has(code ?? ''))
|
|
725
2404
|
throw error;
|
|
726
2405
|
lastError = error;
|
|
727
2406
|
await (0, promises_3.setTimeout)(10);
|
|
728
2407
|
}
|
|
729
|
-
}
|
|
2408
|
+
} while (Date.now() < retryDeadline);
|
|
730
2409
|
throw lastError;
|
|
731
2410
|
};
|
|
732
|
-
await displaceCurrentDirectory();
|
|
733
2411
|
if (asidePath) {
|
|
734
|
-
|
|
2412
|
+
const asideIsSymbolicLink = (await (0, promises_1.lstat)(asidePath)).isSymbolicLink();
|
|
735
2413
|
let restoreError;
|
|
736
|
-
|
|
2414
|
+
let restoreRetryDeadline;
|
|
2415
|
+
let fallbackDisplacedPath;
|
|
2416
|
+
let placeholderIdentity = await identifyRollbackPlaceholder(application.dirPath);
|
|
2417
|
+
const failRestore = async (error) => {
|
|
2418
|
+
try {
|
|
2419
|
+
await makeRollbackPlaceholderMovable(application.dirPath, placeholderIdentity);
|
|
2420
|
+
if (retainReplacement && fallbackDisplacedPath) {
|
|
2421
|
+
const fallbackRetryDeadline = Date.now() + 5000;
|
|
2422
|
+
let fallbackRestoreError;
|
|
2423
|
+
do {
|
|
2424
|
+
let writerDisplacedPath;
|
|
2425
|
+
try {
|
|
2426
|
+
writerDisplacedPath = displaceCurrentDirectorySync();
|
|
2427
|
+
placeholderIdentity = undefined;
|
|
2428
|
+
(0, node_fs_1.renameSync)(fallbackDisplacedPath, application.dirPath);
|
|
2429
|
+
fallbackRestoreError = undefined;
|
|
2430
|
+
}
|
|
2431
|
+
catch (restoreFallbackError) {
|
|
2432
|
+
fallbackRestoreError = restoreFallbackError;
|
|
2433
|
+
}
|
|
2434
|
+
if (writerDisplacedPath) {
|
|
2435
|
+
await (0, promises_1.rm)(writerDisplacedPath, {
|
|
2436
|
+
recursive: true,
|
|
2437
|
+
force: true,
|
|
2438
|
+
maxRetries: 3,
|
|
2439
|
+
retryDelay: 100,
|
|
2440
|
+
});
|
|
2441
|
+
transactionPaths.delete(writerDisplacedPath);
|
|
2442
|
+
}
|
|
2443
|
+
if (fallbackRestoreError &&
|
|
2444
|
+
!retryableRenameCodes.has(fallbackRestoreError.code ?? '')) {
|
|
2445
|
+
throw fallbackRestoreError;
|
|
2446
|
+
}
|
|
2447
|
+
if (fallbackRestoreError) {
|
|
2448
|
+
await (0, promises_3.setTimeout)(10);
|
|
2449
|
+
}
|
|
2450
|
+
else {
|
|
2451
|
+
break;
|
|
2452
|
+
}
|
|
2453
|
+
} while (Date.now() < fallbackRetryDeadline);
|
|
2454
|
+
if (fallbackRestoreError)
|
|
2455
|
+
throw fallbackRestoreError;
|
|
2456
|
+
transactionPaths.delete(fallbackDisplacedPath);
|
|
2457
|
+
transactionPaths.add(await retireExtractionAside(asidePath));
|
|
2458
|
+
}
|
|
2459
|
+
if (placeholderIdentity) {
|
|
2460
|
+
try {
|
|
2461
|
+
const current = await (0, promises_1.lstat)(application.dirPath, { bigint: true });
|
|
2462
|
+
if (current.dev === placeholderIdentity.dev && current.ino === placeholderIdentity.ino) {
|
|
2463
|
+
await (0, promises_1.rm)(application.dirPath, {
|
|
2464
|
+
recursive: true,
|
|
2465
|
+
force: true,
|
|
2466
|
+
maxRetries: 3,
|
|
2467
|
+
retryDelay: 100,
|
|
2468
|
+
});
|
|
2469
|
+
placeholderIdentity = undefined;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
catch (placeholderError) {
|
|
2473
|
+
if (placeholderError.code !== 'ENOENT')
|
|
2474
|
+
throw placeholderError;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
const disposablePaths = new Set(transactionPaths);
|
|
2478
|
+
disposablePaths.delete(asidePath);
|
|
2479
|
+
await cleanupExtractionPaths(application, asideStagingDir, disposablePaths);
|
|
2480
|
+
}
|
|
2481
|
+
catch (fallbackError) {
|
|
2482
|
+
throw new AggregateError([error, fallbackError], `Failed to restore either the previous or replacement ${application.name} component directory`);
|
|
2483
|
+
}
|
|
2484
|
+
throw new Error(`Failed to restore ${asidePath} to the live component directory ${application.dirPath}: ${errorMessage(error)}`, { cause: error });
|
|
2485
|
+
};
|
|
2486
|
+
do {
|
|
737
2487
|
try {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
2488
|
+
if (placeholderIdentity) {
|
|
2489
|
+
const current = (0, node_fs_1.lstatSync)(application.dirPath, { bigint: true });
|
|
2490
|
+
if (current.dev === placeholderIdentity.dev && current.ino === placeholderIdentity.ino) {
|
|
2491
|
+
(0, node_fs_1.chmodSync)(application.dirPath, 0o700);
|
|
2492
|
+
(0, node_fs_1.renameSync)(asidePath, application.dirPath);
|
|
2493
|
+
}
|
|
2494
|
+
else {
|
|
2495
|
+
placeholderIdentity = undefined;
|
|
2496
|
+
await (0, promises_1.rename)(asidePath, application.dirPath);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
else {
|
|
2500
|
+
await (0, promises_1.rename)(asidePath, application.dirPath);
|
|
2501
|
+
}
|
|
2502
|
+
transactionPaths.delete(asidePath);
|
|
2503
|
+
await cleanupExtractionPaths(application, asideStagingDir, transactionPaths);
|
|
2504
|
+
return;
|
|
741
2505
|
}
|
|
742
2506
|
catch (error) {
|
|
743
2507
|
restoreError = error;
|
|
744
|
-
if (!retryableRenameCodes.has(error.code ?? ''))
|
|
745
|
-
|
|
746
|
-
|
|
2508
|
+
if (!retryableRenameCodes.has(error.code ?? '')) {
|
|
2509
|
+
return failRestore(error);
|
|
2510
|
+
}
|
|
2511
|
+
let displacedPath;
|
|
2512
|
+
const displacedPlaceholderIdentity = placeholderIdentity;
|
|
2513
|
+
try {
|
|
2514
|
+
await makeRollbackPlaceholderMovable(application.dirPath, placeholderIdentity);
|
|
2515
|
+
displacedPath = await displaceCurrentDirectory();
|
|
2516
|
+
placeholderIdentity = undefined;
|
|
2517
|
+
if (displacedPath && displacedPlaceholderIdentity) {
|
|
2518
|
+
try {
|
|
2519
|
+
const displaced = await (0, promises_1.lstat)(displacedPath, { bigint: true });
|
|
2520
|
+
if (displaced.dev === displacedPlaceholderIdentity.dev &&
|
|
2521
|
+
displaced.ino === displacedPlaceholderIdentity.ino) {
|
|
2522
|
+
const displacedPlaceholderPath = displacedPath;
|
|
2523
|
+
displacedPath = undefined;
|
|
2524
|
+
await (0, promises_1.rm)(displacedPlaceholderPath, {
|
|
2525
|
+
recursive: true,
|
|
2526
|
+
force: true,
|
|
2527
|
+
maxRetries: 3,
|
|
2528
|
+
retryDelay: 100,
|
|
2529
|
+
});
|
|
2530
|
+
transactionPaths.delete(displacedPlaceholderPath);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
catch (placeholderCleanupError) {
|
|
2534
|
+
application.logger.trace?.(`Cleanup of the ${application.name} rollback placeholder deferred: ${errorMessage(placeholderCleanupError)}`);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
catch (displaceError) {
|
|
2539
|
+
return failRestore(new AggregateError([error, displaceError], `Failed to clear the live ${application.name} component directory for rollback`));
|
|
2540
|
+
}
|
|
2541
|
+
if (displacedPath) {
|
|
2542
|
+
if (fallbackDisplacedPath) {
|
|
2543
|
+
try {
|
|
2544
|
+
await (0, promises_1.rm)(displacedPath, {
|
|
2545
|
+
recursive: true,
|
|
2546
|
+
force: true,
|
|
2547
|
+
maxRetries: 3,
|
|
2548
|
+
retryDelay: 100,
|
|
2549
|
+
});
|
|
2550
|
+
transactionPaths.delete(displacedPath);
|
|
2551
|
+
}
|
|
2552
|
+
catch (cleanupError) {
|
|
2553
|
+
return failRestore(new AggregateError([error, cleanupError], `Failed to discard a displaced ${application.name} writer directory during rollback`));
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
else {
|
|
2557
|
+
fallbackDisplacedPath = displacedPath;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
restoreRetryDeadline ??= Date.now() + 5000;
|
|
2561
|
+
if (process.platform !== 'win32' && process.getuid?.() !== 0) {
|
|
2562
|
+
const stagedPlaceholderPath = (0, node_path_1.join)(asideStagingDir, `.rollback-placeholder-${process.pid}-${Date.now()}-${(0, node_crypto_1.randomUUID)()}`);
|
|
2563
|
+
try {
|
|
2564
|
+
if (asideIsSymbolicLink) {
|
|
2565
|
+
await (0, promises_1.writeFile)(stagedPlaceholderPath, '', { flag: 'wx', mode: 0o000 });
|
|
2566
|
+
}
|
|
2567
|
+
else {
|
|
2568
|
+
await (0, promises_1.mkdir)(stagedPlaceholderPath, { mode: 0o300 });
|
|
2569
|
+
}
|
|
2570
|
+
transactionPaths.add(stagedPlaceholderPath);
|
|
2571
|
+
let placeholderPlacementError;
|
|
2572
|
+
do {
|
|
2573
|
+
let writerDisplacedPath;
|
|
2574
|
+
try {
|
|
2575
|
+
writerDisplacedPath = displaceCurrentDirectorySync();
|
|
2576
|
+
(0, node_fs_1.renameSync)(stagedPlaceholderPath, application.dirPath);
|
|
2577
|
+
if (!asideIsSymbolicLink) {
|
|
2578
|
+
try {
|
|
2579
|
+
(0, node_fs_1.chmodSync)(application.dirPath, 0o100);
|
|
2580
|
+
}
|
|
2581
|
+
catch (chmodError) {
|
|
2582
|
+
try {
|
|
2583
|
+
(0, node_fs_1.renameSync)(application.dirPath, stagedPlaceholderPath);
|
|
2584
|
+
}
|
|
2585
|
+
catch (compensationError) {
|
|
2586
|
+
throw new AggregateError([chmodError, compensationError], `Failed to restrict and then restore the ${application.name} rollback placeholder`);
|
|
2587
|
+
}
|
|
2588
|
+
throw chmodError;
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
transactionPaths.delete(stagedPlaceholderPath);
|
|
2592
|
+
placeholderPlacementError = undefined;
|
|
2593
|
+
}
|
|
2594
|
+
catch (placeholderError) {
|
|
2595
|
+
placeholderPlacementError = placeholderError;
|
|
2596
|
+
}
|
|
2597
|
+
if (writerDisplacedPath) {
|
|
2598
|
+
await (0, promises_1.rm)(writerDisplacedPath, {
|
|
2599
|
+
recursive: true,
|
|
2600
|
+
force: true,
|
|
2601
|
+
maxRetries: 3,
|
|
2602
|
+
retryDelay: 100,
|
|
2603
|
+
});
|
|
2604
|
+
transactionPaths.delete(writerDisplacedPath);
|
|
2605
|
+
}
|
|
2606
|
+
if (placeholderPlacementError &&
|
|
2607
|
+
!retryableRenameCodes.has(placeholderPlacementError.code ?? '')) {
|
|
2608
|
+
throw placeholderPlacementError;
|
|
2609
|
+
}
|
|
2610
|
+
if (!placeholderPlacementError)
|
|
2611
|
+
break;
|
|
2612
|
+
await (0, promises_3.setTimeout)(10);
|
|
2613
|
+
} while (Date.now() < restoreRetryDeadline);
|
|
2614
|
+
if (transactionPaths.has(stagedPlaceholderPath)) {
|
|
2615
|
+
throw new Error(`Failed to place the ${application.name} rollback placeholder before the deadline: ${errorMessage(placeholderPlacementError)}`, { cause: placeholderPlacementError });
|
|
2616
|
+
}
|
|
2617
|
+
const placeholder = await (0, promises_1.lstat)(application.dirPath, { bigint: true });
|
|
2618
|
+
placeholderIdentity = { dev: placeholder.dev, ino: placeholder.ino };
|
|
2619
|
+
}
|
|
2620
|
+
catch (placeholderError) {
|
|
2621
|
+
return failRestore(new AggregateError([error, placeholderError], `Failed to block a live ${application.name} writer during rollback`));
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
747
2624
|
await (0, promises_3.setTimeout)(10);
|
|
748
2625
|
}
|
|
2626
|
+
} while (restoreRetryDeadline !== undefined && Date.now() < restoreRetryDeadline);
|
|
2627
|
+
return failRestore(restoreError);
|
|
2628
|
+
}
|
|
2629
|
+
try {
|
|
2630
|
+
await displaceCurrentDirectory();
|
|
2631
|
+
}
|
|
2632
|
+
catch (displaceError) {
|
|
2633
|
+
try {
|
|
2634
|
+
await (0, promises_1.rm)(application.dirPath, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
2635
|
+
await cleanupExtractionPaths(application, asideStagingDir, transactionPaths);
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
catch (removeError) {
|
|
2639
|
+
throw new AggregateError([displaceError, removeError], `Failed to remove the partial ${application.name} component directory after extraction failed`);
|
|
749
2640
|
}
|
|
750
|
-
if (!restored)
|
|
751
|
-
throw restoreError;
|
|
752
2641
|
}
|
|
753
|
-
await
|
|
2642
|
+
await cleanupExtractionPaths(application, asideStagingDir, transactionPaths);
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* The one definition of how Harper invokes a package manager to install dependencies; every npm
|
|
2646
|
+
* entry point composes its arguments here rather than assembling its own.
|
|
2647
|
+
*/
|
|
2648
|
+
function packageManagerInstallArguments(packageManagerName, allowInstallScripts, force = false) {
|
|
2649
|
+
const args = ['install'];
|
|
2650
|
+
if (force)
|
|
2651
|
+
args.push('--force');
|
|
2652
|
+
if (packageManagerName === 'npm')
|
|
2653
|
+
args.push('--omit=dev', '--no-audit', '--no-fund');
|
|
2654
|
+
if (!allowInstallScripts)
|
|
2655
|
+
args.push('--ignore-scripts');
|
|
2656
|
+
return args;
|
|
754
2657
|
}
|
|
755
2658
|
/**
|
|
756
|
-
* Install
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
* package manager, `npm`.
|
|
2659
|
+
* Install a component's dependencies into `buildDirPath` — the live path, or a candidate under
|
|
2660
|
+
* `.deploy-staging`. Explicit rather than repointing `application.dirPath`, which is read after preparation
|
|
2661
|
+
* too and would name a vanished directory if any failure path skipped the restore.
|
|
760
2662
|
*
|
|
761
|
-
*
|
|
2663
|
+
* Uses a configured `application.install` command, a package manager derived from the application's
|
|
2664
|
+
* `package.json#devEngines`, or the default, `npm`. Returns early when `node_modules` already exists or
|
|
2665
|
+
* when the manifest has no automatic install work. An explicitly selected non-npm manager is always
|
|
2666
|
+
* allowed to inspect its own workspace configuration, even when the root manifest has no production
|
|
2667
|
+
* dependencies.
|
|
762
2668
|
*
|
|
763
|
-
*
|
|
2669
|
+
* May be called from any Harper thread as part of a serialized preparation.
|
|
764
2670
|
*/
|
|
765
|
-
async function installApplication(application) {
|
|
2671
|
+
async function installApplication(application, buildDirPath = application.dirPath) {
|
|
766
2672
|
let packageJSON;
|
|
767
2673
|
try {
|
|
768
|
-
packageJSON = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(
|
|
2674
|
+
packageJSON = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(buildDirPath, 'package.json'), 'utf8'));
|
|
769
2675
|
}
|
|
770
2676
|
catch (err) {
|
|
771
2677
|
if (err.code !== 'ENOENT')
|
|
@@ -776,7 +2682,7 @@ async function installApplication(application) {
|
|
|
776
2682
|
}
|
|
777
2683
|
try {
|
|
778
2684
|
// Does node_modules exist?
|
|
779
|
-
await (0, promises_1.access)((0, node_path_1.join)(
|
|
2685
|
+
await (0, promises_1.access)((0, node_path_1.join)(buildDirPath, 'node_modules'), promises_1.constants.F_OK);
|
|
780
2686
|
application.logger.info(`Application ${application.name} already has node_modules; skipping install and treating the runtime as opaque for redeploy comparison`);
|
|
781
2687
|
application.installationIsOpaque = true;
|
|
782
2688
|
return;
|
|
@@ -792,7 +2698,7 @@ async function installApplication(application) {
|
|
|
792
2698
|
const customOnLine = application.onInstallLine
|
|
793
2699
|
? (stream, line) => application.onInstallLine(command, stream, line)
|
|
794
2700
|
: undefined;
|
|
795
|
-
const { stdout, stderr, code } = await nonInteractiveSpawn(application.name, command, args,
|
|
2701
|
+
const { stdout, stderr, code } = await nonInteractiveSpawn(application.name, command, args, buildDirPath, application.install?.timeout, customOnLine, application.npmUserconfigPath);
|
|
796
2702
|
// if it succeeds, return
|
|
797
2703
|
if (code === 0) {
|
|
798
2704
|
application.installationIsOpaque = true;
|
|
@@ -807,8 +2713,17 @@ async function installApplication(application) {
|
|
|
807
2713
|
// and throw a descriptive error
|
|
808
2714
|
throw new Error(`Failed to install dependencies for ${application.name} using custom install command: ${application.install.command}. Exit code: ${code}`);
|
|
809
2715
|
}
|
|
810
|
-
|
|
2716
|
+
const allowInstallScripts = !!application.install?.allowInstallScripts;
|
|
811
2717
|
const { packageManager } = packageJSON.devEngines || {};
|
|
2718
|
+
if (dependencyFieldHasWork(packageJSON, 'devDependencies')) {
|
|
2719
|
+
application.logger.warn(`Application ${application.name} declares devDependencies; automatic npm installation omits them, while explicitly selected non-npm package managers retain their own install defaults. Use install_command when deployment requires custom behavior`);
|
|
2720
|
+
}
|
|
2721
|
+
if (!packageHasAutomaticInstallWork(packageJSON) &&
|
|
2722
|
+
!(allowInstallScripts && packageHasAllowedInstallLifecycleWork(packageJSON))) {
|
|
2723
|
+
application.logger.info(`Application ${application.name} has no production package work; skipping install`);
|
|
2724
|
+
return;
|
|
2725
|
+
}
|
|
2726
|
+
// Next, try package.json devEngines field
|
|
812
2727
|
// Custom package manager specified
|
|
813
2728
|
if (packageManager) {
|
|
814
2729
|
// On any given system we want to leverage the `name` to match the package manager executable
|
|
@@ -833,8 +2748,7 @@ async function installApplication(application) {
|
|
|
833
2748
|
const pmOnLine = application.onInstallLine
|
|
834
2749
|
? (stream, line) => application.onInstallLine(packageManager.name, stream, line)
|
|
835
2750
|
: undefined;
|
|
836
|
-
const { stdout, stderr, code } = await nonInteractiveSpawn(application.name, (application.packageManagerPrefix ? application.packageManagerPrefix + ' ' : '') + packageManager.name,
|
|
837
|
-
application.dirPath, application.install?.timeout, pmOnLine, application.npmUserconfigPath);
|
|
2751
|
+
const { stdout, stderr, code } = await nonInteractiveSpawn(application.name, (application.packageManagerPrefix ? application.packageManagerPrefix + ' ' : '') + packageManager.name, packageManagerInstallArguments(packageManager.name, allowInstallScripts), buildDirPath, application.install?.timeout, pmOnLine, application.npmUserconfigPath);
|
|
838
2752
|
// if it succeeds, return
|
|
839
2753
|
if (code === 0) {
|
|
840
2754
|
if (application.install?.allowInstallScripts)
|
|
@@ -866,13 +2780,18 @@ async function installApplication(application) {
|
|
|
866
2780
|
// But then fall through to installing with npm
|
|
867
2781
|
}
|
|
868
2782
|
// Finally, default to running `npm install`
|
|
869
|
-
const npmInstallArgs =
|
|
870
|
-
|
|
871
|
-
|
|
2783
|
+
const npmInstallArgs = packageManagerInstallArguments('npm', allowInstallScripts, true);
|
|
2784
|
+
// A candidate build is installed at a staging path and then RENAMED to the live path, so nothing npm
|
|
2785
|
+
// writes may depend on the build location. npm links a `file:` dependency relatively on POSIX, which
|
|
2786
|
+
// survives the move — but as an absolute junction on Windows, which does not, so the dependency stops
|
|
2787
|
+
// resolving once the tree moves. `--install-links` copies instead of linking, leaving no path to break.
|
|
2788
|
+
// win32 and candidate builds only, since it does change how `file:` dependencies behave.
|
|
2789
|
+
if (process.platform === 'win32' && buildDirPath !== application.dirPath)
|
|
2790
|
+
npmInstallArgs.push('--install-links');
|
|
872
2791
|
const npmOnLine = application.onInstallLine
|
|
873
2792
|
? (stream, line) => application.onInstallLine('npm', stream, line)
|
|
874
2793
|
: undefined;
|
|
875
|
-
const { stdout, stderr, code } = await nonInteractiveSpawn(application.name, (application.packageManagerPrefix ? application.packageManagerPrefix + ' ' : '') + 'npm', npmInstallArgs,
|
|
2794
|
+
const { stdout, stderr, code } = await nonInteractiveSpawn(application.name, (application.packageManagerPrefix ? application.packageManagerPrefix + ' ' : '') + 'npm', npmInstallArgs, buildDirPath, application.install?.timeout, npmOnLine, application.npmUserconfigPath);
|
|
876
2795
|
// if it succeeds, return
|
|
877
2796
|
if (code === 0) {
|
|
878
2797
|
if (application.install?.allowInstallScripts)
|
|
@@ -893,6 +2812,7 @@ class Application {
|
|
|
893
2812
|
name;
|
|
894
2813
|
payload;
|
|
895
2814
|
packageIdentifier;
|
|
2815
|
+
packLocalDirectory;
|
|
896
2816
|
install;
|
|
897
2817
|
onInstallLine;
|
|
898
2818
|
dirPath;
|
|
@@ -917,6 +2837,7 @@ class Application {
|
|
|
917
2837
|
constructor({ name, payload, packageIdentifier, install, onInstallLine, credentials }) {
|
|
918
2838
|
this.name = name;
|
|
919
2839
|
this.payload = payload;
|
|
2840
|
+
this.packLocalDirectory = shouldPackLocalDirectory(packageIdentifier);
|
|
920
2841
|
this.packageIdentifier = packageIdentifier && derivePackageIdentifier(packageIdentifier);
|
|
921
2842
|
this.install = install;
|
|
922
2843
|
this.onInstallLine = onInstallLine;
|
|
@@ -1033,7 +2954,12 @@ exports.Application = Application;
|
|
|
1033
2954
|
* during the installation process in order to actually resolve what the user specifies for a
|
|
1034
2955
|
* component matching some of npm's package resolution rules.
|
|
1035
2956
|
*/
|
|
2957
|
+
function isBareAbsolutePackagePath(packageIdentifier) {
|
|
2958
|
+
return (0, node_path_1.isAbsolute)(packageIdentifier) || node_path_1.win32.isAbsolute(packageIdentifier);
|
|
2959
|
+
}
|
|
1036
2960
|
function derivePackageIdentifier(packageIdentifier) {
|
|
2961
|
+
if (isBareAbsolutePackagePath(packageIdentifier))
|
|
2962
|
+
return `file:${packageIdentifier}`;
|
|
1037
2963
|
if (packageIdentifier.includes(':')) {
|
|
1038
2964
|
return packageIdentifier;
|
|
1039
2965
|
}
|
|
@@ -1045,59 +2971,76 @@ function derivePackageIdentifier(packageIdentifier) {
|
|
|
1045
2971
|
}
|
|
1046
2972
|
return `github:${packageIdentifier}`;
|
|
1047
2973
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
* threads by the preparation lock below.
|
|
1053
|
-
*
|
|
1054
|
-
* Bracketed with `deploy:start`/`deploy:end` lifecycle broadcasts so every
|
|
1055
|
-
* Harper thread's file watchers can suppress restart-on-change events while
|
|
1056
|
-
* the component directory is being rewritten — see harper#488 and
|
|
1057
|
-
* `components/deployLifecycle.ts`. The broadcast is best-effort: if it fails
|
|
1058
|
-
* (e.g. workers haven't started yet during initial install), the deploy still
|
|
1059
|
-
* proceeds.
|
|
1060
|
-
*
|
|
1061
|
-
* @param application The application to prepare.
|
|
1062
|
-
* @returns A promise that resolves when all preparation steps complete.
|
|
1063
|
-
*/
|
|
1064
|
-
async function prepareApplication(application) {
|
|
2974
|
+
function shouldPackLocalDirectory(packageIdentifier, platform = process.platform) {
|
|
2975
|
+
return platform === 'win32' && !!packageIdentifier && isBareAbsolutePackagePath(packageIdentifier);
|
|
2976
|
+
}
|
|
2977
|
+
async function prepareApplication(application, options = {}) {
|
|
1065
2978
|
const deploymentId = await (0, deployLifecycle_ts_1.broadcastDeployStart)(application.name);
|
|
1066
2979
|
try {
|
|
1067
2980
|
const commandTimeoutMs = application.install?.timeout ?? DEFAULT_COMMAND_TIMEOUT_MS;
|
|
1068
2981
|
await (0, componentPreparationLock_ts_1.withComponentPreparationLock)(application.dirPath, async () => {
|
|
2982
|
+
const asideStagingDir = extractionStagingDirectory(application.dirPath);
|
|
2983
|
+
let recoveryPending = true;
|
|
2984
|
+
try {
|
|
2985
|
+
await (0, promises_1.lstat)(asideStagingDir);
|
|
2986
|
+
}
|
|
2987
|
+
catch (error) {
|
|
2988
|
+
if (error.code !== 'ENOENT')
|
|
2989
|
+
throw error;
|
|
2990
|
+
recoveryPending = false;
|
|
2991
|
+
}
|
|
2992
|
+
// BEFORE the legacy pass. That pass refuses to restore while a journal survives, so skipping
|
|
2993
|
+
// this would not lose data — it would just stall the deploy behind its own unsettled state.
|
|
2994
|
+
await settleJournaledActivationsForComponent((0, node_path_1.dirname)(application.dirPath), application.name);
|
|
2995
|
+
if (recoveryPending) {
|
|
2996
|
+
await ensureExtractionStagingDirectory(asideStagingDir);
|
|
2997
|
+
await recoverOrCleanupStaleExtractionPaths(application, asideStagingDir);
|
|
2998
|
+
}
|
|
1069
2999
|
const previousPackageMetadata = await readInstalledPackageMetadata(application.dirPath);
|
|
1070
|
-
|
|
3000
|
+
// Determined before the swap, because both trees exist then: the runtime comparison below
|
|
3001
|
+
// wants the live version and the candidate side by side.
|
|
3002
|
+
application.isNewComponent = !(await (0, promises_1.lstat)(application.dirPath).then(() => true, (error) => {
|
|
3003
|
+
if (error.code === 'ENOENT')
|
|
3004
|
+
return false;
|
|
3005
|
+
throw error;
|
|
3006
|
+
}));
|
|
1071
3007
|
try {
|
|
1072
|
-
// Materialize the per-deploy `.npmrc` before
|
|
1073
|
-
//
|
|
3008
|
+
// Materialize the per-deploy `.npmrc` before the build so both `npm pack` and `npm install`
|
|
3009
|
+
// authenticate against the private registry; always remove it afterward.
|
|
1074
3010
|
await application.writeTransientNpmrc();
|
|
3011
|
+
let candidateDirPath;
|
|
1075
3012
|
try {
|
|
1076
|
-
//
|
|
1077
|
-
//
|
|
1078
|
-
//
|
|
1079
|
-
// allowed to run) executes.
|
|
3013
|
+
// Backstop only: the builder closes the session as soon as extraction is done, so the
|
|
3014
|
+
// credential is already gone before any install script runs. This finally covers the paths
|
|
3015
|
+
// that fail before it gets there.
|
|
1080
3016
|
await application.startGitCredentialSession();
|
|
1081
|
-
|
|
3017
|
+
candidateDirPath = await buildCandidateApplication(application, deploymentId);
|
|
1082
3018
|
}
|
|
1083
3019
|
finally {
|
|
1084
3020
|
await application.cleanupGitCredentialSession();
|
|
1085
3021
|
}
|
|
1086
|
-
await installApplication(application);
|
|
1087
|
-
if (!application.isNewComponent) {
|
|
1088
|
-
const currentPackageMetadata = await readInstalledPackageMetadata(application.dirPath);
|
|
1089
|
-
application.packageMetadataChanged = installedRuntimeChanged(previousPackageMetadata, currentPackageMetadata, application.installationIsOpaque);
|
|
1090
|
-
}
|
|
1091
|
-
await extraction?.commit();
|
|
1092
|
-
}
|
|
1093
|
-
catch (error) {
|
|
1094
3022
|
try {
|
|
1095
|
-
|
|
3023
|
+
// Validated while the previous version is still the one serving, so a candidate that
|
|
3024
|
+
// installs cleanly but throws at load is rejected without ever having been live.
|
|
3025
|
+
await options.validateCandidate?.(candidateDirPath);
|
|
3026
|
+
if (!application.isNewComponent) {
|
|
3027
|
+
application.packageMetadataChanged = installedRuntimeChanged(previousPackageMetadata, await readInstalledPackageMetadata(candidateDirPath), application.installationIsOpaque);
|
|
3028
|
+
}
|
|
3029
|
+
await activateCandidateApplication(application, deploymentId);
|
|
1096
3030
|
}
|
|
1097
|
-
catch (
|
|
1098
|
-
|
|
3031
|
+
catch (error) {
|
|
3032
|
+
// The builder's own cleanup only covers a failed BUILD. A rejected validation, or an
|
|
3033
|
+
// activation that was cleanly compensated, would otherwise leave a whole installed
|
|
3034
|
+
// dependency tree under this deployment id — repeated rejections fill the volume.
|
|
3035
|
+
//
|
|
3036
|
+
// NOT when compensation itself failed. There the previous version is not back and the live
|
|
3037
|
+
// path may be absent, and the candidate plus its `.complete` marker and journal are exactly
|
|
3038
|
+
// what recovery needs to roll the validated deploy forward at the next start. Discarding
|
|
3039
|
+
// them there trades a bounded disk cost for a component with no version at all.
|
|
3040
|
+
if (!compensationIncomplete(error))
|
|
3041
|
+
await discardCandidate(application, deploymentId);
|
|
3042
|
+
throw error;
|
|
1099
3043
|
}
|
|
1100
|
-
throw error;
|
|
1101
3044
|
}
|
|
1102
3045
|
finally {
|
|
1103
3046
|
await application.cleanupTransientNpmrc();
|
|
@@ -1403,19 +3346,6 @@ function buildNpmrcContent(registryCredentials) {
|
|
|
1403
3346
|
}
|
|
1404
3347
|
return lines.join('\n') + '\n';
|
|
1405
3348
|
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Execute a command (using `spawn`) with stdin ignored.
|
|
1408
|
-
*
|
|
1409
|
-
* Stdout is logged chunk-by-chunk. Stderr is buffered and then logged line-by-line.
|
|
1410
|
-
*
|
|
1411
|
-
* Rejects with an error if the command fails or times out.
|
|
1412
|
-
*
|
|
1413
|
-
* @param command The command to run.
|
|
1414
|
-
* @param args The arguments to pass to the command.
|
|
1415
|
-
* @param cwd The working directory for the command.
|
|
1416
|
-
* @param timeoutMs The timeout for the command in milliseconds. Defaults to 5 minutes.
|
|
1417
|
-
* @returns A promise that resolves when the command completes.
|
|
1418
|
-
*/
|
|
1419
3349
|
/**
|
|
1420
3350
|
* Line-buffered split that emits complete `\n`-terminated lines as they
|
|
1421
3351
|
* arrive, holding any partial trailing fragment until the next chunk or `flush()`.
|
|
@@ -1454,9 +3384,20 @@ function createLineSplitter(onLine) {
|
|
|
1454
3384
|
};
|
|
1455
3385
|
}
|
|
1456
3386
|
/**
|
|
1457
|
-
*
|
|
1458
|
-
* spawn. The keys are decrypted to a transient 0700 dir
|
|
1459
|
-
* soon as the process settles — on success, failure, and
|
|
3387
|
+
* Execute a command (using `spawn`) with stdin ignored, with the deploy's SSH key material
|
|
3388
|
+
* materialized only for the duration of the spawn. The keys are decrypted to a transient 0700 dir
|
|
3389
|
+
* (see `materializeGitSSH`) and removed as soon as the process settles — on success, failure, and
|
|
3390
|
+
* timeout alike.
|
|
3391
|
+
*
|
|
3392
|
+
* Stdout is logged chunk-by-chunk. Stderr is buffered and then logged line-by-line.
|
|
3393
|
+
*
|
|
3394
|
+
* Rejects with an error if the command fails or times out.
|
|
3395
|
+
*
|
|
3396
|
+
* @param command The command to run.
|
|
3397
|
+
* @param args The arguments to pass to the command.
|
|
3398
|
+
* @param cwd The working directory for the command.
|
|
3399
|
+
* @param timeoutMs The timeout for the command in milliseconds. Defaults to DEFAULT_COMMAND_TIMEOUT_MS.
|
|
3400
|
+
* @returns A promise that resolves when the command completes.
|
|
1460
3401
|
*/
|
|
1461
3402
|
async function nonInteractiveSpawn(applicationName, command, args, cwd, timeoutMs = DEFAULT_COMMAND_TIMEOUT_MS, onLine, npmUserconfigPath, gitCredentialEnv) {
|
|
1462
3403
|
const gitSSH = await materializeGitSSH();
|
|
@@ -1503,6 +3444,7 @@ function spawnWithEnv(applicationName, command, args, cwd, timeoutMs, onLine, np
|
|
|
1503
3444
|
if (process.platform === 'win32' && command === 'npm') {
|
|
1504
3445
|
command = 'npm.cmd';
|
|
1505
3446
|
}
|
|
3447
|
+
const spawnLogger = harper_logger_ts_1.default.loggerWithTag(`${applicationName}:spawn:${command}`);
|
|
1506
3448
|
const childProcess = (0, node_child_process_1.spawn)(command, args, {
|
|
1507
3449
|
shell: true,
|
|
1508
3450
|
cwd,
|
|
@@ -1591,7 +3533,19 @@ function spawnWithEnv(applicationName, command, args, cwd, timeoutMs, onLine, np
|
|
|
1591
3533
|
reject(error);
|
|
1592
3534
|
}
|
|
1593
3535
|
});
|
|
1594
|
-
childProcess.on('
|
|
3536
|
+
childProcess.on('exit', (code, signal) => {
|
|
3537
|
+
spawnLogger.debug?.(`Direct child exited with code ${code}, signal ${signal}; awaiting stdio close`);
|
|
3538
|
+
});
|
|
3539
|
+
childProcess.on('close', async (code, signal) => {
|
|
3540
|
+
if (didTimeout) {
|
|
3541
|
+
spawnLogger.debug?.(`Child stdio closed with code ${code}, signal ${signal}; timeout path owns process-tree confirmation`);
|
|
3542
|
+
}
|
|
3543
|
+
else if (trackedProcessId) {
|
|
3544
|
+
spawnLogger.debug?.(`Child stdio closed with code ${code}, signal ${signal}; confirming process-tree termination`);
|
|
3545
|
+
}
|
|
3546
|
+
else {
|
|
3547
|
+
spawnLogger.debug?.(`Child stdio closed with code ${code}, signal ${signal}; no process tree was tracked`);
|
|
3548
|
+
}
|
|
1595
3549
|
resolveClose();
|
|
1596
3550
|
clearTimeout(timeout);
|
|
1597
3551
|
// A successful direct-child exit does not prove the process group is empty: a custom
|
|
@@ -1613,6 +3567,7 @@ function spawnWithEnv(applicationName, command, args, cwd, timeoutMs, onLine, np
|
|
|
1613
3567
|
}
|
|
1614
3568
|
return;
|
|
1615
3569
|
}
|
|
3570
|
+
spawnLogger.debug?.(`Process tree termination confirmed after command close with code ${code}`);
|
|
1616
3571
|
untrackProcessGroup();
|
|
1617
3572
|
}
|
|
1618
3573
|
// When didTimeout is true, the timeout path's own terminateProcessTree(...).then(...) owns
|
|
@@ -1624,7 +3579,6 @@ function spawnWithEnv(applicationName, command, args, cwd, timeoutMs, onLine, np
|
|
|
1624
3579
|
if (stderr) {
|
|
1625
3580
|
printStd(applicationName, command, stderr, 'stderr');
|
|
1626
3581
|
}
|
|
1627
|
-
harper_logger_ts_1.default.loggerWithTag(`${applicationName}:spawn:${command}`).debug?.(`Process exited with code ${code}`);
|
|
1628
3582
|
if (didTimeout || didSettle)
|
|
1629
3583
|
return;
|
|
1630
3584
|
didSettle = true;
|
|
@@ -1647,13 +3601,7 @@ class CommandTimeoutError extends Error {
|
|
|
1647
3601
|
}
|
|
1648
3602
|
}
|
|
1649
3603
|
function processGroupIsAlive(processGroupId) {
|
|
1650
|
-
|
|
1651
|
-
process.kill(-processGroupId, 0);
|
|
1652
|
-
return true;
|
|
1653
|
-
}
|
|
1654
|
-
catch (error) {
|
|
1655
|
-
return error.code === 'EPERM';
|
|
1656
|
-
}
|
|
3604
|
+
return (0, manageThreads_js_1.isProcessGroupAlive)(processGroupId);
|
|
1657
3605
|
}
|
|
1658
3606
|
async function waitForProcessGroupExit(processGroupId, timeoutMs) {
|
|
1659
3607
|
const deadline = performance.now() + timeoutMs;
|