@harperfast/harper 5.2.10 → 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 -3
- package/dist/resources/DatabaseTransaction.js +460 -134
- 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 +30 -2
- 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 -10
- 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 +1071 -197
- package/dist/resources/Table.js.map +1 -1
- package/dist/resources/auditStore.d.ts +11 -2
- package/dist/resources/auditStore.js +183 -18
- 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 -9
- package/dist/resources/databases.js +1247 -525
- 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 -32
- 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 +5 -0
- package/dist/server/storageReclamation.js +16 -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 -4
- package/dist/server/threads/manageThreads.js +517 -72
- 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 +235 -233
- package/package.json +8 -7
- package/resources/DESIGN.md +114 -52
- package/resources/DatabaseTransaction.ts +522 -130
- package/resources/LMDBTransaction.ts +26 -4
- package/resources/PrimaryRocksDatabase.ts +29 -3
- 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 -10
- package/resources/RocksTransactionLogStore.ts +78 -21
- package/resources/Table.ts +1107 -164
- package/resources/auditStore.ts +187 -21
- package/resources/blob.ts +1029 -110
- package/resources/branchDatabase.ts +941 -0
- package/resources/crdt.ts +76 -12
- package/resources/databases.ts +1354 -522
- 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 -32
- 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 +13 -0
- package/server/threads/itc.js +11 -1
- package/server/threads/manageThreads.js +526 -63
- 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-Br06zdMA.js → Chat-BnCBegQz.js} +1 -1
- package/studio/web/assets/{FloatingChat-BWImX5fA.js → FloatingChat-CoDW1ySS.js} +3 -3
- package/studio/web/assets/{apiToken-DN0nmDsq.js → apiToken-Bwk5BLXW.js} +1 -1
- package/studio/web/assets/{applications-kSxVoyeU.js → applications-DHxGi7JH.js} +1 -1
- package/studio/web/assets/{cssMode-C1JeufH5.js → cssMode-s0cWI-_M.js} +1 -1
- package/studio/web/assets/{editor-qoo9CrGO.js → editor-DNcRHK54.js} +1 -1
- package/studio/web/assets/{html-Dt4IIy04.js → html-Bdssedlg.js} +1 -1
- package/studio/web/assets/{htmlMode-DXgKKr4C.js → htmlMode-CoDlJ3fw.js} +1 -1
- package/studio/web/assets/{index-6onkYFOG.js → index-D6sxmFLR.js} +5 -5
- package/studio/web/assets/{index.lazy-BrCFnpNJ.js → index.lazy-tmU5BS8s.js} +1 -1
- package/studio/web/assets/{javascript-DNCQGUBc.js → javascript-B8meVSTH.js} +1 -1
- package/studio/web/assets/{jsonMode-CR6HWruP.js → jsonMode-DpIPd35T.js} +1 -1
- package/studio/web/assets/{languageServices-BM4fI4rS.js → languageServices-C_5FMJzQ.js} +1 -1
- package/studio/web/assets/{lspLanguageFeatures-DSa1ttcD.js → lspLanguageFeatures-BIzNBzPK.js} +1 -1
- package/studio/web/assets/{notifications-BHXLnh6x.js → notifications-CQf18QKb.js} +1 -1
- package/studio/web/assets/{notifications-CUmtIA6z.js → notifications-CvZivSbh.js} +1 -1
- package/studio/web/assets/{profile-8BeFSF3j.js → profile-DdOwtntb.js} +1 -1
- package/studio/web/assets/{regions-C8qR0HhD.js → regions-n69fwagr.js} +1 -1
- package/studio/web/assets/{register-B4n5i0SD.js → register-PfWTCXWB.js} +2 -2
- package/studio/web/assets/{setComponentFile-g0_B0lgX.js → setComponentFile-Bg6O7X0S.js} +1 -1
- package/studio/web/assets/{setup-B0CTj_Q5.js → setup-CUx_aUDl.js} +2 -2
- package/studio/web/assets/{status-C6Yib7-K.js → status-D7BVKqX9.js} +1 -1
- package/studio/web/assets/{toggleHighContrast-Dgta7bVi.js → toggleHighContrast-DBSyXzMr.js} +1 -1
- package/studio/web/assets/{tsMode-CH_jHvU-.js → tsMode-BByKCjBS.js} +1 -1
- package/studio/web/assets/{typescript-Co9LCXd5.js → typescript-DDLnLpw9.js} +1 -1
- package/studio/web/assets/{useEntityRestURL-wKC8NsC_.js → useEntityRestURL-31CHGaHk.js} +1 -1
- package/studio/web/assets/{workers-CWeLxCXA.js → workers-pR3jRY9D.js} +1 -1
- package/studio/web/assets/{xml-BadC-0Rk.js → xml-2iRnMhQO.js} +1 -1
- package/studio/web/assets/{yaml-BiUfxPbC.js → yaml-Bf92gJpd.js} +1 -1
- package/studio/web/index.html +1 -1
- 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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
const { realExit } = require("./workerProcessGuard.js");
|
|
6
6
|
const { Worker, MessageChannel, parentPort, isMainThread, threadId, workerData } = require('worker_threads');
|
|
7
7
|
const { spawn, spawnSync } = require('node:child_process');
|
|
8
|
-
const { readFileSync } = require('node:fs');
|
|
8
|
+
const { readdirSync, readFileSync, readlinkSync } = require('node:fs');
|
|
9
9
|
const { setTimeout: delay } = require('node:timers/promises');
|
|
10
10
|
const { join, isAbsolute, extname } = require('path');
|
|
11
11
|
const { pathToFileURL } = require('url');
|
|
@@ -19,7 +19,10 @@ const { randomBytes } = require('crypto');
|
|
|
19
19
|
const { _assignPackageExport } = require('../../globals.js');
|
|
20
20
|
const { PACKAGE_ROOT } = require('../../utility/packageUtils.js');
|
|
21
21
|
const { resolvePreloadModules } = require("./resolvePreload.js");
|
|
22
|
+
const { resolveThreadHeapMemoryMb } = require("./threadHeapMemory.js");
|
|
22
23
|
const { getConfigPath } = require("../../config/configUtils.js");
|
|
24
|
+
const { resolveWatchTarget } = require("../../utility/watchPath.js");
|
|
25
|
+
const { DIRECTORY_POLLING_FALLBACK_OPTIONS, claimLostNativeWatchError, guardedWatch, isWatcherExhaustionError, warnWatcherFallback, } = require("../../utility/watcherFallback.js");
|
|
23
26
|
let importModules;
|
|
24
27
|
function getImportModules() {
|
|
25
28
|
if (importModules === undefined)
|
|
@@ -32,7 +35,6 @@ function getRequireModules() {
|
|
|
32
35
|
requireModules = resolvePreloadModules(envMgr.get(hdbTerms.CONFIG_PARAMS.THREADS_PRELOADREQUIRE), getConfigPath(hdbTerms.CONFIG_PARAMS.COMPONENTSROOT), 'threads.preloadRequire');
|
|
33
36
|
return requireModules;
|
|
34
37
|
}
|
|
35
|
-
const chokidar = require('chokidar');
|
|
36
38
|
const isBun = typeof globalThis.Bun !== 'undefined';
|
|
37
39
|
const MB = 1024 * 1024;
|
|
38
40
|
const workers = []; // these are our child workers that we are managing
|
|
@@ -44,8 +46,11 @@ const MAX_UNEXPECTED_RESTARTS = 50;
|
|
|
44
46
|
// down mid-disposal crashes the process, so give that teardown more room before the forced backstop.
|
|
45
47
|
let threadTerminationTimeout = process.env.DEV_MODE === 'true' || process.env.DEV_MODE === '1' ? 30000 : 10000;
|
|
46
48
|
const RESTART_TYPE = 'restart';
|
|
49
|
+
const RESTART_PROGRESS_HEARTBEAT_MS = 15000;
|
|
47
50
|
const REQUEST_THREAD_INFO = 'request_thread_info';
|
|
48
51
|
const RESOURCE_REPORT = 'resource_report';
|
|
52
|
+
const OS_THREAD_ID = 'os-thread-id';
|
|
53
|
+
const STUCK_WORKER_REPORT = 'stuck-worker-report';
|
|
49
54
|
const THREAD_INFO = 'thread_info';
|
|
50
55
|
const ADDED_PORT = 'added-port';
|
|
51
56
|
const ACKNOWLEDGEMENT = 'ack';
|
|
@@ -141,16 +146,14 @@ module.exports = {
|
|
|
141
146
|
beginProcessShutdown,
|
|
142
147
|
registerWorkerDataProvider,
|
|
143
148
|
onThreadExit,
|
|
149
|
+
hasThreadExited,
|
|
150
|
+
notifyThreadExit,
|
|
144
151
|
registerProcessGroup,
|
|
145
152
|
unregisterProcessGroup,
|
|
153
|
+
isProcessGroupAlive,
|
|
146
154
|
isThreadRunning,
|
|
147
155
|
waitUntilConfirmedGone,
|
|
148
156
|
restartNumber: workerData?.restartNumber || 1,
|
|
149
|
-
// Identifies this process incarnation, where the PID cannot: a container reuses PID 1. Minted once
|
|
150
|
-
// on the main thread and carried to workers, so live siblings agree on it — one derived per thread
|
|
151
|
-
// would not. `undefined` on a worker started without it; consumers must fall back, not treat that
|
|
152
|
-
// as a mismatch.
|
|
153
|
-
processIncarnation: workerData ? workerData.processIncarnation : randomBytes(8).toString('hex'),
|
|
154
157
|
};
|
|
155
158
|
connectedPorts.onMessageByType = onMessageByType;
|
|
156
159
|
connectedPorts.sendToThread = function (threadId, message) {
|
|
@@ -218,7 +221,6 @@ const RESERVED_WORKER_DATA_KEYS = [
|
|
|
218
221
|
'workerCount',
|
|
219
222
|
'name',
|
|
220
223
|
'restartNumber',
|
|
221
|
-
'processIncarnation',
|
|
222
224
|
'ticketKeys',
|
|
223
225
|
'noServerStart',
|
|
224
226
|
'__proto__', // never a legitimate payload name; spread would define it as an own property
|
|
@@ -299,6 +301,17 @@ if (!parentPort) {
|
|
|
299
301
|
if (worker)
|
|
300
302
|
recordResourceReport(worker, message);
|
|
301
303
|
});
|
|
304
|
+
onMessageByType(OS_THREAD_ID, (message, worker) => {
|
|
305
|
+
if (worker)
|
|
306
|
+
worker.osThreadId = message.osThreadId;
|
|
307
|
+
});
|
|
308
|
+
onMessageByType(STUCK_WORKER_REPORT, (message) => {
|
|
309
|
+
for (const threadId of message.threadIds) {
|
|
310
|
+
const worker = workers.find((worker) => worker.threadId === threadId);
|
|
311
|
+
if (worker)
|
|
312
|
+
logStuckWorkerDiagnostics(worker);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
302
315
|
onMessageByType(AWAIT_PROCESS_GROUP_TERMINATION, async (message, worker) => {
|
|
303
316
|
if (!worker)
|
|
304
317
|
return;
|
|
@@ -311,6 +324,7 @@ if (!parentPort) {
|
|
|
311
324
|
}
|
|
312
325
|
// postMessage type listeners that are registered in other ways or can be registered later
|
|
313
326
|
listenersByType.set(hdbTerms.ITC_EVENT_TYPES.CHILD_STARTED, null);
|
|
327
|
+
listenersByType.set(hdbTerms.ITC_EVENT_TYPES.CHILD_STARTUP_PHASE, null);
|
|
314
328
|
listenersByType.set(hdbTerms.ITC_EVENT_TYPES.SCHEMA, null);
|
|
315
329
|
listenersByType.set(hdbTerms.ITC_EVENT_TYPES.USER, null);
|
|
316
330
|
listenersByType.set(hdbTerms.ITC_EVENT_TYPES.COMPONENT_STATUS_REQUEST, null);
|
|
@@ -346,7 +360,7 @@ function startWorker(path, options = {}) {
|
|
|
346
360
|
let availableMemory = process.constrainedMemory?.() || totalmem(); // used constrained memory if it is available
|
|
347
361
|
// and lower than total memory
|
|
348
362
|
availableMemory = Math.min(availableMemory, totalmem(), 20000 * MB);
|
|
349
|
-
const maxOldMemory = envMgr.get(hdbTerms.CONFIG_PARAMS.THREADS_MAXHEAPMEMORY) ??
|
|
363
|
+
const maxOldMemory = resolveThreadHeapMemoryMb(envMgr.get(hdbTerms.CONFIG_PARAMS.THREADS_MAXHEAPMEMORY)) ??
|
|
350
364
|
Math.max(Math.floor(availableMemory / MB / (10 + (options.threadCount || 1) / 4)), 512);
|
|
351
365
|
// Max young memory space (semi-space for scavenger) is 1/128 of max memory (limited to 16-64). For most of our m5
|
|
352
366
|
// machines this will be 64MB (less for t3's). This is based on recommendations from:
|
|
@@ -408,7 +422,6 @@ function startWorker(path, options = {}) {
|
|
|
408
422
|
workerCount: (workerCount = options.threadCount),
|
|
409
423
|
name: options.name,
|
|
410
424
|
restartNumber: module.exports.restartNumber,
|
|
411
|
-
processIncarnation: module.exports.processIncarnation,
|
|
412
425
|
ticketKeys: getTicketKeys(),
|
|
413
426
|
},
|
|
414
427
|
transferList: portsToSend,
|
|
@@ -445,8 +458,10 @@ function startWorker(path, options = {}) {
|
|
|
445
458
|
options.unexpectedRestarts = worker.unexpectedRestarts + 1;
|
|
446
459
|
startWorker(path, options);
|
|
447
460
|
}
|
|
448
|
-
else
|
|
449
|
-
harperLogger.error(`Thread has been restarted ${worker.
|
|
461
|
+
else {
|
|
462
|
+
harperLogger.error(`Thread has been restarted ${worker.unexpectedRestarts} times and will not be restarted`);
|
|
463
|
+
options.onRestartExhausted?.(worker);
|
|
464
|
+
}
|
|
450
465
|
}
|
|
451
466
|
});
|
|
452
467
|
workers.push(worker);
|
|
@@ -465,13 +480,20 @@ const OVERLAPPING_RESTART_TYPES = [hdbTerms.THREAD_TYPES.HTTP];
|
|
|
465
480
|
* threads at the same time we shutdown new ones. However, we usually want to limit how many we do at once to avoid
|
|
466
481
|
* excessive load and to keep things responsive. This parameter throttles the restarts to minimize load from
|
|
467
482
|
* thread startups.
|
|
468
|
-
* @
|
|
483
|
+
* @param onProgress Called each time a worker has been replaced (or its replacement has been given
|
|
484
|
+
* up on), so a caller waiting on a wide pool can tell a slow restart from a stalled one.
|
|
485
|
+
* @returns {Promise<{workersKeptOnOldCode: number, replacementsNotStarted: number}|{declined: true}|undefined>}
|
|
486
|
+
* from the main thread, how many workers were left running the old code and how many replacements
|
|
487
|
+
* never reported that they started — or `{declined: true}` when the process is already shutting down;
|
|
488
|
+
* from a worker, nothing — the restart is handed to the main thread.
|
|
469
489
|
*/
|
|
470
490
|
async function restartWorkers(name = null, maxWorkersDown = Math.max(Math.floor(workerCount / 8), 1), // restart 1/8 of the threads at a time, but at least 1
|
|
471
|
-
startReplacementThreads = true) {
|
|
491
|
+
startReplacementThreads = true, onProgress = null) {
|
|
472
492
|
if (isMainThread) {
|
|
493
|
+
// Declining is not the same as delegating: a caller reporting on the restart must not read this
|
|
494
|
+
// as "another thread is completing it".
|
|
473
495
|
if (processShuttingDown && startReplacementThreads)
|
|
474
|
-
return;
|
|
496
|
+
return { declined: true };
|
|
475
497
|
try {
|
|
476
498
|
// we do this because it is possible for a component to chdir to itself, get re-deployed and then the cwd
|
|
477
499
|
// inode link is invalid and it can cause a lot of problems. But process.cwd() still returns the path, for
|
|
@@ -487,7 +509,17 @@ startReplacementThreads = true) {
|
|
|
487
509
|
// This is here to prevent circular dependencies
|
|
488
510
|
if (startReplacementThreads) {
|
|
489
511
|
const { loadRootComponents } = require('../loadRootComponents.js');
|
|
490
|
-
|
|
512
|
+
// Installing and loading every root component reports nothing and can outlast a caller's idle
|
|
513
|
+
// window on its own (a cold npm cache, a large dependency graph), so beat while it runs. The
|
|
514
|
+
// caller's absolute ceiling is what bounds a load that never finishes.
|
|
515
|
+
const loading = setInterval(() => onProgress?.(), RESTART_PROGRESS_HEARTBEAT_MS).unref();
|
|
516
|
+
try {
|
|
517
|
+
await loadRootComponents();
|
|
518
|
+
}
|
|
519
|
+
finally {
|
|
520
|
+
clearInterval(loading);
|
|
521
|
+
}
|
|
522
|
+
onProgress?.();
|
|
491
523
|
}
|
|
492
524
|
module.exports.restartNumber++;
|
|
493
525
|
if (maxWorkersDown < 1) {
|
|
@@ -496,7 +528,17 @@ startReplacementThreads = true) {
|
|
|
496
528
|
maxWorkersDown = maxWorkersDown * workers.length;
|
|
497
529
|
}
|
|
498
530
|
// make a copy of the workers before iterating them, as the workers array mutates a lot during this
|
|
499
|
-
let waitingToFinish = []; // promises for workers we
|
|
531
|
+
let waitingToFinish = []; // promises for workers we are replacing, spliced as each is replaced
|
|
532
|
+
// Every replacement that was started without being awaited first, so this function can still
|
|
533
|
+
// resolve only once each one is accepting connections.
|
|
534
|
+
let replacementsStarting = [];
|
|
535
|
+
// A replacement that never came up leaves the pool in one of two very different states, and a
|
|
536
|
+
// caller waiting on this restart needs them apart: the pre-start path keeps the *old* worker
|
|
537
|
+
// serving old code, while a replacement that exits after its predecessor is already gone only
|
|
538
|
+
// costs capacity until startWorker's auto-restart brings a fresh one up.
|
|
539
|
+
let workersKeptOnOldCode = 0;
|
|
540
|
+
let replacementsNotStarted = 0;
|
|
541
|
+
let replacementsFailedToStart = 0;
|
|
500
542
|
// We can only start the replacement *before* the old worker releases its port when the OS lets
|
|
501
543
|
// both listen on the same port at once (SO_REUSEPORT). Without that — Windows (no SO_REUSEPORT),
|
|
502
544
|
// macOS (unreliable SO_REUSEPORT, so workers bind exclusively), and Bun — the replacement can't
|
|
@@ -508,7 +550,9 @@ startReplacementThreads = true) {
|
|
|
508
550
|
// thread keeps serving the HTTP ports throughout. This ordering is also what lets
|
|
509
551
|
// listenOnPorts() treat a dedicated listener's EADDRINUSE as an external conflict.
|
|
510
552
|
const canPreStartReplacement = process.platform !== 'win32' && process.platform !== 'darwin' && !isBun;
|
|
511
|
-
|
|
553
|
+
const restarting = workers.slice(0);
|
|
554
|
+
for (let index = 0; index < restarting.length; index++) {
|
|
555
|
+
const worker = restarting[index];
|
|
512
556
|
// Terminal shutdown: stop replacing workers mid-loop — the guard for every replacement start below.
|
|
513
557
|
if (processShuttingDown && startReplacementThreads)
|
|
514
558
|
break;
|
|
@@ -569,6 +613,8 @@ startReplacementThreads = true) {
|
|
|
569
613
|
// protection if it is still alive (it may have exited on its own during the wait).
|
|
570
614
|
if (workers.includes(worker))
|
|
571
615
|
worker.wasShutdown = false;
|
|
616
|
+
workersKeptOnOldCode++;
|
|
617
|
+
onProgress?.();
|
|
572
618
|
continue;
|
|
573
619
|
}
|
|
574
620
|
}
|
|
@@ -591,8 +637,16 @@ startReplacementThreads = true) {
|
|
|
591
637
|
// Overlapping types we couldn't pre-start (Windows/Bun): start the replacement now that the old
|
|
592
638
|
// worker is releasing its port. server.close() stops accepting immediately, so the port frees up
|
|
593
639
|
// well before the replacement finishes booting and binds.
|
|
594
|
-
|
|
595
|
-
|
|
640
|
+
let replacementStarting;
|
|
641
|
+
if (overlapping && startReplacementThreads && !canPreStartReplacement && !processShuttingDown) {
|
|
642
|
+
replacementStarting = whenWorkerStarted(worker.startCopy()).then((started) => {
|
|
643
|
+
if (!started)
|
|
644
|
+
replacementsFailedToStart++;
|
|
645
|
+
onProgress?.();
|
|
646
|
+
return started;
|
|
647
|
+
});
|
|
648
|
+
replacementsStarting.push(replacementStarting);
|
|
649
|
+
}
|
|
596
650
|
let whenDone = new Promise((resolve) => {
|
|
597
651
|
// in case the exit inside the thread doesn't timeout, force it from the outside
|
|
598
652
|
const armTerminate = (delay) => setTimeout(() => {
|
|
@@ -620,29 +674,57 @@ startReplacementThreads = true) {
|
|
|
620
674
|
// buggy/rogue message can't defer the force-kill unboundedly; a shrink (drain-done reset)
|
|
621
675
|
// passes through untouched. See boundedTerminateDelay for the arithmetic + its unit tests.
|
|
622
676
|
const { boundedTerminateDelay, getShutdownDrainCeilingMs } = require("../../components/shutdownDrain.js");
|
|
623
|
-
|
|
677
|
+
const delay = boundedTerminateDelay(deadlineMs, Date.now(), threadTerminationTimeout * 2, getShutdownDrainCeilingMs());
|
|
678
|
+
timeout = armTerminate(delay);
|
|
679
|
+
// The worker is telling us it has work still moving and how long it may take, so pass that
|
|
680
|
+
// on: a caller waiting on the restart must not treat a live drain as a stalled one.
|
|
681
|
+
onProgress?.(Date.now() + delay);
|
|
624
682
|
};
|
|
625
683
|
worker.on('exit', () => {
|
|
626
684
|
clearTimeout(timeout);
|
|
685
|
+
onProgress?.();
|
|
627
686
|
worker.extendTerminateDeadline = undefined;
|
|
628
|
-
const index = waitingToFinish.indexOf(whenDone);
|
|
629
|
-
if (index > -1)
|
|
630
|
-
waitingToFinish.splice(index, 1);
|
|
631
687
|
// non-overlapping types have no advance replacement, so start it once the old one is gone
|
|
632
688
|
if (!overlapping && startReplacementThreads && !processShuttingDown)
|
|
633
689
|
worker.startCopy();
|
|
634
690
|
resolve();
|
|
635
691
|
});
|
|
636
692
|
});
|
|
637
|
-
|
|
693
|
+
// A worker counts as replaced only once its replacement is accepting connections, not merely
|
|
694
|
+
// once it has exited. This promise is held unawaited between throttle points, so it must not
|
|
695
|
+
// be able to reject.
|
|
696
|
+
const replaced = (replacementStarting ? Promise.all([whenDone, replacementStarting]) : whenDone)
|
|
697
|
+
.catch((error) => harperLogger.warn('Error waiting for a worker to be replaced', error))
|
|
698
|
+
.then(() => {
|
|
699
|
+
const at = waitingToFinish.indexOf(replaced);
|
|
700
|
+
if (at > -1)
|
|
701
|
+
waitingToFinish.splice(at, 1);
|
|
702
|
+
});
|
|
703
|
+
waitingToFinish.push(replaced);
|
|
638
704
|
if (waitingToFinish.length >= maxWorkersDown) {
|
|
639
|
-
// throttle how many workers are
|
|
705
|
+
// throttle how many workers are down at once to limit load
|
|
640
706
|
await Promise.race(waitingToFinish);
|
|
641
707
|
}
|
|
708
|
+
// Readiness throttling bounds how many workers are down at once, but not how many *fail*: with
|
|
709
|
+
// replacements that never come up, walking the rest of the pool would leave nothing serving.
|
|
710
|
+
// The workers not yet touched are still running the old code, which beats none running at all.
|
|
711
|
+
if (replacementsFailedToStart >= maxWorkersDown) {
|
|
712
|
+
const untouched = restarting
|
|
713
|
+
.slice(index + 1)
|
|
714
|
+
// a worker that exited on its own mid-restart is spliced out of `workers` and
|
|
715
|
+
// auto-restarted onto the new code (see the exit handler above); it is not still on
|
|
716
|
+
// the previous code even though this loop never got to it.
|
|
717
|
+
.filter((other) => (!name || other.name === name) && !other.wasShutdown && workers.includes(other)).length;
|
|
718
|
+
harperLogger.error(`${replacementsFailedToStart} replacement worker thread(s) did not start; stopping this restart with ${untouched} worker(s) still on the previous code`);
|
|
719
|
+
workersKeptOnOldCode += untouched;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
642
722
|
}
|
|
643
|
-
// seems appropriate to wait for this to finish, but the API doesn't actually wait for this function
|
|
644
|
-
// to finish, so not that important
|
|
645
723
|
await Promise.all(waitingToFinish);
|
|
724
|
+
// A caller awaiting this needs it to mean "the pool is serving the new code", so wait out the
|
|
725
|
+
// replacements that could only be started once their predecessor released its exclusive ports.
|
|
726
|
+
replacementsNotStarted = (await Promise.all(replacementsStarting)).filter((started) => !started).length;
|
|
727
|
+
return { workersKeptOnOldCode, replacementsNotStarted };
|
|
646
728
|
}
|
|
647
729
|
else {
|
|
648
730
|
parentPort.postMessage({
|
|
@@ -651,6 +733,51 @@ startReplacementThreads = true) {
|
|
|
651
733
|
});
|
|
652
734
|
}
|
|
653
735
|
}
|
|
736
|
+
/**
|
|
737
|
+
* Resolve once a newly started worker reports that it is accepting connections, or gives up on it.
|
|
738
|
+
* There is no old worker left to fall back on here, so a replacement that fails to start is left to
|
|
739
|
+
* startWorker's own auto-restart handling; this only stops waiting on it.
|
|
740
|
+
* @param newWorker The replacement worker
|
|
741
|
+
* @returns {Promise<boolean>} whether the worker reported that it started
|
|
742
|
+
*/
|
|
743
|
+
function whenWorkerStarted(newWorker) {
|
|
744
|
+
return new Promise((resolve) => {
|
|
745
|
+
const cleanup = () => {
|
|
746
|
+
clearTimeout(timeout);
|
|
747
|
+
newWorker.off('message', startListener);
|
|
748
|
+
newWorker.off('exit', exitListener);
|
|
749
|
+
};
|
|
750
|
+
const timeout = setTimeout(() => {
|
|
751
|
+
harperLogger.error('Replacement worker did not start in time', newWorker.threadId);
|
|
752
|
+
cleanup();
|
|
753
|
+
// Its predecessor is already gone, so a replacement wedged in boot is a worker slot serving
|
|
754
|
+
// nothing until the process restarts. Stop it and let startWorker's exit handling replace it.
|
|
755
|
+
if (isBun) {
|
|
756
|
+
// terminate() triggers a NAPI segfault in Bun; ask the worker to self-exit instead.
|
|
757
|
+
try {
|
|
758
|
+
newWorker.postMessage({ type: FORCE_EXIT });
|
|
759
|
+
}
|
|
760
|
+
catch { }
|
|
761
|
+
}
|
|
762
|
+
else
|
|
763
|
+
newWorker.terminate();
|
|
764
|
+
resolve(false);
|
|
765
|
+
}, Math.max(threadTerminationTimeout * 2, 60000)).unref();
|
|
766
|
+
const startListener = (message) => {
|
|
767
|
+
if (message.type === hdbTerms.ITC_EVENT_TYPES.CHILD_STARTED) {
|
|
768
|
+
cleanup();
|
|
769
|
+
resolve(true);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
const exitListener = () => {
|
|
773
|
+
harperLogger.warn('Replacement worker exited before starting', newWorker.threadId);
|
|
774
|
+
cleanup();
|
|
775
|
+
resolve(false);
|
|
776
|
+
};
|
|
777
|
+
newWorker.on('message', startListener);
|
|
778
|
+
newWorker.on('exit', exitListener);
|
|
779
|
+
});
|
|
780
|
+
}
|
|
654
781
|
function shutdownWorkers(name) {
|
|
655
782
|
return restartWorkers(name, Infinity, false);
|
|
656
783
|
}
|
|
@@ -784,15 +911,146 @@ function broadcastWithAcknowledgement(message, timeout = DEFAULT_ACK_TIMEOUT_MS)
|
|
|
784
911
|
timer = undefined;
|
|
785
912
|
const stuck = [];
|
|
786
913
|
for (let ackHandler of [...pending]) {
|
|
787
|
-
stuck.push(ackHandler.port
|
|
914
|
+
stuck.push(ackHandler.port);
|
|
788
915
|
ackHandler(); // same cleanup path as an ack/close; drives waitingCount to 0 and resolves
|
|
789
916
|
}
|
|
790
|
-
harperLogger.warn(`ITC broadcast (type ${message.type}) not acknowledged by worker thread(s) ${stuck.join(', ')} within ${timeout}ms; proceeding best-effort`);
|
|
917
|
+
harperLogger.warn(`ITC broadcast (type ${message.type}) not acknowledged by worker thread(s) ${stuck.map((port) => port?.threadId).join(', ')} within ${timeout}ms; proceeding best-effort`);
|
|
918
|
+
if (isMainThread)
|
|
919
|
+
for (let port of stuck)
|
|
920
|
+
logStuckWorkerDiagnostics(port);
|
|
921
|
+
else if (parentPort) {
|
|
922
|
+
// Only main holds the Worker objects (and tids), so a worker-originated timeout is sampled there.
|
|
923
|
+
const threadIds = stuck.map((port) => port?.threadId).filter((threadId) => threadId > 0);
|
|
924
|
+
if (threadIds.length > 0)
|
|
925
|
+
parentPort.postMessage({ type: STUCK_WORKER_REPORT, threadIds });
|
|
926
|
+
}
|
|
791
927
|
}, timeout);
|
|
792
928
|
timer.unref?.();
|
|
793
929
|
}
|
|
794
930
|
});
|
|
795
931
|
}
|
|
932
|
+
// Linux only: /proc/thread-self resolves to <pid>/task/<tid> for the calling thread.
|
|
933
|
+
function getOsThreadId() {
|
|
934
|
+
try {
|
|
935
|
+
const tid = Number(readlinkSync('/proc/thread-self').split('/').pop());
|
|
936
|
+
return Number.isInteger(tid) && tid > 0 ? tid : undefined;
|
|
937
|
+
}
|
|
938
|
+
catch {
|
|
939
|
+
return undefined;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function readTaskFile(tid, name) {
|
|
943
|
+
try {
|
|
944
|
+
return readFileSync(`/proc/self/task/${tid}/${name}`, 'utf8').trim();
|
|
945
|
+
}
|
|
946
|
+
catch {
|
|
947
|
+
return undefined;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
// Kernel-side view of one thread. Every field is best-effort and reported individually, since
|
|
951
|
+
// wchan/syscall need ptrace read access that a hardened container may deny while stat is open.
|
|
952
|
+
function finiteOrUndefined(value) {
|
|
953
|
+
const number = Number(value);
|
|
954
|
+
return Number.isFinite(number) ? number : undefined;
|
|
955
|
+
}
|
|
956
|
+
function readOsThreadState(tid) {
|
|
957
|
+
const thread = { tid };
|
|
958
|
+
const stat = readTaskFile(tid, 'stat');
|
|
959
|
+
if (stat !== undefined) {
|
|
960
|
+
// Fields after the parenthesized comm, so state is [0], utime/stime [11]/[12], starttime [19].
|
|
961
|
+
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
962
|
+
thread.state = fields[0];
|
|
963
|
+
const utime = finiteOrUndefined(fields[11]);
|
|
964
|
+
const stime = finiteOrUndefined(fields[12]);
|
|
965
|
+
if (utime !== undefined && stime !== undefined)
|
|
966
|
+
thread.cpuTicks = utime + stime;
|
|
967
|
+
thread.startTime = fields[19];
|
|
968
|
+
}
|
|
969
|
+
const wchan = readTaskFile(tid, 'wchan');
|
|
970
|
+
if (wchan !== undefined)
|
|
971
|
+
thread.wchan = wchan;
|
|
972
|
+
// First token only: the syscall number, "running", or -1 (blocked outside a syscall). The
|
|
973
|
+
// remainder is argument registers and the stack/instruction pointers, which don't belong in a log.
|
|
974
|
+
const syscall = readTaskFile(tid, 'syscall');
|
|
975
|
+
if (syscall !== undefined)
|
|
976
|
+
thread.syscall = syscall.split(' ')[0];
|
|
977
|
+
const status = readTaskFile(tid, 'status');
|
|
978
|
+
if (status !== undefined) {
|
|
979
|
+
thread.voluntarySwitches = finiteOrUndefined(/^voluntary_ctxt_switches:\s*(\d+)/m.exec(status)?.[1]);
|
|
980
|
+
thread.nonvoluntarySwitches = finiteOrUndefined(/^nonvoluntary_ctxt_switches:\s*(\d+)/m.exec(status)?.[1]);
|
|
981
|
+
}
|
|
982
|
+
return thread;
|
|
983
|
+
}
|
|
984
|
+
function snapshotWorkerThread(worker) {
|
|
985
|
+
const snapshot = { at: Date.now() };
|
|
986
|
+
if (worker.resources?.updated)
|
|
987
|
+
snapshot.sinceResourceReport = snapshot.at - worker.resources.updated;
|
|
988
|
+
const eventLoop = worker.performance?.eventLoopUtilization?.();
|
|
989
|
+
if (eventLoop)
|
|
990
|
+
snapshot.eventLoop = { idle: eventLoop.idle, active: eventLoop.active };
|
|
991
|
+
if (worker.osThreadId)
|
|
992
|
+
snapshot.osThread = readOsThreadState(worker.osThreadId);
|
|
993
|
+
return snapshot;
|
|
994
|
+
}
|
|
995
|
+
function describeThreadState(thread) {
|
|
996
|
+
return `state=${thread.state ?? '?'} wchan=${thread.wchan ?? '?'} syscall=${thread.syscall ?? '?'}`;
|
|
997
|
+
}
|
|
998
|
+
function describeSnapshot(snapshot) {
|
|
999
|
+
const parts = [
|
|
1000
|
+
snapshot.sinceResourceReport === undefined
|
|
1001
|
+
? 'no resource report received'
|
|
1002
|
+
: `last resource report ${snapshot.sinceResourceReport}ms ago`,
|
|
1003
|
+
];
|
|
1004
|
+
if (snapshot.eventLoop)
|
|
1005
|
+
parts.push(`event loop active ${Math.round(snapshot.eventLoop.active)}ms idle ${Math.round(snapshot.eventLoop.idle)}ms`);
|
|
1006
|
+
const thread = snapshot.osThread;
|
|
1007
|
+
if (!thread)
|
|
1008
|
+
parts.push('os thread state unavailable');
|
|
1009
|
+
else
|
|
1010
|
+
parts.push(`os tid ${thread.tid} ${describeThreadState(thread)} cpuTicks=${thread.cpuTicks ?? '?'} ctxtSwitches=${thread.voluntarySwitches ?? '?'}/${thread.nonvoluntarySwitches ?? '?'}`);
|
|
1011
|
+
return parts.join('; ');
|
|
1012
|
+
}
|
|
1013
|
+
function describeDelta(before, after) {
|
|
1014
|
+
return Number.isFinite(before) && Number.isFinite(after) ? `+${after - before}` : '?';
|
|
1015
|
+
}
|
|
1016
|
+
function describeProgress(first, second) {
|
|
1017
|
+
const parts = [];
|
|
1018
|
+
if (first.eventLoop && second.eventLoop)
|
|
1019
|
+
parts.push(`event loop active +${Math.round(second.eventLoop.active - first.eventLoop.active)}ms idle +${Math.round(second.eventLoop.idle - first.eventLoop.idle)}ms`);
|
|
1020
|
+
const before = first.osThread;
|
|
1021
|
+
const after = second.osThread;
|
|
1022
|
+
if (before && after)
|
|
1023
|
+
parts.push(`cpuTicks ${describeDelta(before.cpuTicks, after.cpuTicks)} ctxtSwitches ${describeDelta(before.voluntarySwitches, after.voluntarySwitches)}/${describeDelta(before.nonvoluntarySwitches, after.nonvoluntarySwitches)} ${describeThreadState(after)}`);
|
|
1024
|
+
return parts.join('; ');
|
|
1025
|
+
}
|
|
1026
|
+
// A blocked event loop cannot report itself; two kernel-state samples a second apart separate
|
|
1027
|
+
// "parked on a lock" (no CPU ticks, no context switches) from "spinning".
|
|
1028
|
+
const STUCK_WORKER_SAMPLE_INTERVAL_MS = 1000;
|
|
1029
|
+
const STUCK_WORKER_DIAGNOSTIC_COOLDOWN_MS = 30000;
|
|
1030
|
+
function logStuckWorkerDiagnostics(worker) {
|
|
1031
|
+
if (!worker || !workers.includes(worker))
|
|
1032
|
+
return;
|
|
1033
|
+
const now = Date.now();
|
|
1034
|
+
if (worker.stuckDiagnosticAt !== undefined && now - worker.stuckDiagnosticAt < STUCK_WORKER_DIAGNOSTIC_COOLDOWN_MS)
|
|
1035
|
+
return;
|
|
1036
|
+
worker.stuckDiagnosticAt = now;
|
|
1037
|
+
const threadId = worker.threadId; // Node resets it to -1 once the worker exits
|
|
1038
|
+
const first = snapshotWorkerThread(worker);
|
|
1039
|
+
harperLogger.warn(`Worker thread ${threadId} at ack timeout: ${describeSnapshot(first)}`);
|
|
1040
|
+
if (!first.eventLoop && !first.osThread)
|
|
1041
|
+
return;
|
|
1042
|
+
setTimeout(() => {
|
|
1043
|
+
if (!workers.includes(worker)) {
|
|
1044
|
+
harperLogger.warn(`Worker thread ${threadId} exited before its follow-up sample`);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
const second = snapshotWorkerThread(worker);
|
|
1048
|
+
// A recycled tid after a thread exit would attribute another thread's activity to this worker.
|
|
1049
|
+
if (second.osThread && second.osThread.startTime !== first.osThread?.startTime)
|
|
1050
|
+
second.osThread = undefined;
|
|
1051
|
+
harperLogger.warn(`Worker thread ${threadId} over the next ${second.at - first.at}ms: ${describeProgress(first, second) || 'no further state available'}`);
|
|
1052
|
+
}, STUCK_WORKER_SAMPLE_INTERVAL_MS).unref();
|
|
1053
|
+
}
|
|
796
1054
|
function sendThreadInfo(targetWorker) {
|
|
797
1055
|
targetWorker.postMessage({
|
|
798
1056
|
type: THREAD_INFO,
|
|
@@ -864,6 +1122,9 @@ if (parentPort && workerData?.addPorts) {
|
|
|
864
1122
|
// parentPort so sendToThread(0, ...) and similar lookups can route back to main.
|
|
865
1123
|
parentPort.threadId = 0;
|
|
866
1124
|
addPort(parentPort);
|
|
1125
|
+
const osThreadId = getOsThreadId();
|
|
1126
|
+
if (osThreadId !== undefined)
|
|
1127
|
+
parentPort.postMessage({ type: OS_THREAD_ID, osThreadId });
|
|
867
1128
|
for (let i = 0, l = workerData.addPorts.length; i < l; i++) {
|
|
868
1129
|
let port = workerData.addPorts[i];
|
|
869
1130
|
port.threadId = workerData.addThreadIds[i];
|
|
@@ -913,16 +1174,22 @@ if (parentPort && workerData?.addPorts) {
|
|
|
913
1174
|
}
|
|
914
1175
|
});
|
|
915
1176
|
let awaitTerminationRequestId = 0;
|
|
916
|
-
awaitProcessGroupTermination = (ownerThreadId) => new Promise((resolve) => {
|
|
1177
|
+
awaitProcessGroupTermination = (ownerThreadId, signal) => new Promise((resolve) => {
|
|
917
1178
|
// Deliberately no timeout: a contender must not reclaim a dead owner's lock while its
|
|
918
1179
|
// process group might still be alive and mutating files, so this mirrors the unbounded
|
|
919
|
-
// wait Application.ts's waitForConfirmedTermination uses for the same reason.
|
|
1180
|
+
// wait Application.ts's waitForConfirmedTermination uses for the same reason. A caller
|
|
1181
|
+
// that needs its own bound (isThreadRunning) passes `signal` so this listener still gets
|
|
1182
|
+
// torn down when that caller gives up, instead of leaking for the life of the worker.
|
|
920
1183
|
const requestId = ++awaitTerminationRequestId;
|
|
921
1184
|
parentPort.on('message', receiveConfirmation);
|
|
1185
|
+
signal?.addEventListener('abort', cleanup, { once: true });
|
|
922
1186
|
parentPort.postMessage({ type: AWAIT_PROCESS_GROUP_TERMINATION, ownerThreadId, requestId });
|
|
1187
|
+
function cleanup() {
|
|
1188
|
+
parentPort.off('message', receiveConfirmation);
|
|
1189
|
+
}
|
|
923
1190
|
function receiveConfirmation(message) {
|
|
924
1191
|
if (message.type === PROCESS_GROUP_TERMINATION_CONFIRMED && message.requestId === requestId) {
|
|
925
|
-
|
|
1192
|
+
cleanup();
|
|
926
1193
|
resolve();
|
|
927
1194
|
}
|
|
928
1195
|
}
|
|
@@ -953,34 +1220,144 @@ const processGroupsByThread = new Map();
|
|
|
953
1220
|
// window component-preparation locking exists to close.
|
|
954
1221
|
const pendingProcessGroupTerminations = new Map();
|
|
955
1222
|
const PROCESS_GROUP_TERMINATION_POLL_MS = 25;
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
//
|
|
959
|
-
//
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
function
|
|
964
|
-
|
|
965
|
-
|
|
1223
|
+
const ZOMBIE_GROUP_MEMBER_SCAN_INTERVAL_MS = 1000;
|
|
1224
|
+
const PROCESS_GROUP_LIVENESS_WARNING_MS = 30000;
|
|
1225
|
+
// Bounds isThreadRunning's own wait (below); Application.ts's waitForConfirmedTermination stays
|
|
1226
|
+
// deliberately unbounded.
|
|
1227
|
+
const THREAD_RUNNING_TERMINATION_BACKSTOP_MS = PROCESS_GROUP_LIVENESS_WARNING_MS;
|
|
1228
|
+
const zombieGroupScanTimes = new Map();
|
|
1229
|
+
const processGroupLivenessStates = new Map();
|
|
1230
|
+
function processGroupExists(processGroupId) {
|
|
1231
|
+
try {
|
|
1232
|
+
process.kill(-processGroupId, 0);
|
|
1233
|
+
return true;
|
|
1234
|
+
}
|
|
1235
|
+
catch (error) {
|
|
1236
|
+
return error.code === 'EPERM';
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function processProbeError(error) {
|
|
1240
|
+
return error?.code ?? error?.message ?? String(error ?? 'unknown error');
|
|
1241
|
+
}
|
|
1242
|
+
function processGroupLeaderState(processGroupId, platform, readStat) {
|
|
1243
|
+
if (platform !== 'linux') {
|
|
1244
|
+
return { state: 'unknown', reason: `zombie-process detection is unavailable on ${platform}` };
|
|
1245
|
+
}
|
|
966
1246
|
let stat;
|
|
967
1247
|
try {
|
|
968
|
-
stat =
|
|
1248
|
+
stat = readStat(`/proc/${processGroupId}/stat`, 'utf8');
|
|
969
1249
|
}
|
|
970
|
-
catch {
|
|
971
|
-
|
|
1250
|
+
catch (error) {
|
|
1251
|
+
if (error.code === 'ENOENT' || error.code === 'ESRCH')
|
|
1252
|
+
return { state: 'missing' };
|
|
1253
|
+
return {
|
|
1254
|
+
state: 'unknown',
|
|
1255
|
+
reason: `reading /proc/${processGroupId}/stat failed (${processProbeError(error)})`,
|
|
1256
|
+
};
|
|
972
1257
|
}
|
|
973
|
-
|
|
974
|
-
|
|
1258
|
+
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
1259
|
+
if (Number(fields[2]) !== processGroupId)
|
|
1260
|
+
return { state: 'missing' };
|
|
1261
|
+
return { state: fields[0] === 'Z' ? 'zombie' : 'alive' };
|
|
975
1262
|
}
|
|
976
|
-
function
|
|
1263
|
+
function scanLinuxProcessGroup(processGroupId, readDirectory, readStat) {
|
|
1264
|
+
let processIds;
|
|
977
1265
|
try {
|
|
978
|
-
|
|
1266
|
+
processIds = readDirectory('/proc');
|
|
979
1267
|
}
|
|
980
1268
|
catch (error) {
|
|
981
|
-
return
|
|
1269
|
+
return {
|
|
1270
|
+
isAlive: null,
|
|
1271
|
+
reason: `reading /proc failed (${processProbeError(error)})`,
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
for (const processId of processIds) {
|
|
1275
|
+
if (!/^\d+$/.test(processId))
|
|
1276
|
+
continue;
|
|
1277
|
+
let stat;
|
|
1278
|
+
try {
|
|
1279
|
+
stat = readStat(`/proc/${processId}/stat`, 'utf8');
|
|
1280
|
+
}
|
|
1281
|
+
catch (error) {
|
|
1282
|
+
if (error.code === 'ENOENT' || error.code === 'ESRCH')
|
|
1283
|
+
continue; // already gone
|
|
1284
|
+
// EACCES/EPERM (e.g. hidepid/ProtectProc) can only happen on a pid we don't own — we
|
|
1285
|
+
// spawned our own group's members as this same user, so their stat is always readable —
|
|
1286
|
+
// so it's not one of ours. Anything else is genuinely unknown, not "not ours".
|
|
1287
|
+
if (error.code === 'EACCES' || error.code === 'EPERM')
|
|
1288
|
+
continue;
|
|
1289
|
+
return {
|
|
1290
|
+
isAlive: null,
|
|
1291
|
+
reason: `reading /proc/${processId}/stat failed (${processProbeError(error)})`,
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
1295
|
+
const pgrp = Number(fields[2]);
|
|
1296
|
+
if (!Number.isFinite(pgrp)) {
|
|
1297
|
+
return { isAlive: null, reason: `/proc/${processId}/stat had an unparseable process-group field` };
|
|
1298
|
+
}
|
|
1299
|
+
if (pgrp !== processGroupId)
|
|
1300
|
+
continue;
|
|
1301
|
+
if (fields[0] !== 'Z')
|
|
1302
|
+
return { isAlive: true, reason: `a live member was observed at pid ${processId}` };
|
|
1303
|
+
}
|
|
1304
|
+
return { isAlive: false };
|
|
1305
|
+
}
|
|
1306
|
+
function keepProcessGroupAlive(processGroupId, reason, observationTime, warn) {
|
|
1307
|
+
let livenessState = processGroupLivenessStates.get(processGroupId);
|
|
1308
|
+
if (!livenessState) {
|
|
1309
|
+
livenessState = { observedAt: observationTime, reason, warned: false };
|
|
1310
|
+
processGroupLivenessStates.set(processGroupId, livenessState);
|
|
982
1311
|
}
|
|
983
|
-
|
|
1312
|
+
else {
|
|
1313
|
+
livenessState.reason = reason;
|
|
1314
|
+
}
|
|
1315
|
+
if (!livenessState.warned && observationTime - livenessState.observedAt >= PROCESS_GROUP_LIVENESS_WARNING_MS) {
|
|
1316
|
+
livenessState.warned = true;
|
|
1317
|
+
warn(`Process group ${processGroupId} termination remains unconfirmed after ${PROCESS_GROUP_LIVENESS_WARNING_MS}ms: ${livenessState.reason}`);
|
|
1318
|
+
}
|
|
1319
|
+
return true;
|
|
1320
|
+
}
|
|
1321
|
+
function clearProcessGroupLivenessState(processGroupId) {
|
|
1322
|
+
zombieGroupScanTimes.delete(processGroupId);
|
|
1323
|
+
processGroupLivenessStates.delete(processGroupId);
|
|
1324
|
+
}
|
|
1325
|
+
function isProcessGroupAlive(processGroupId, options) {
|
|
1326
|
+
const platform = options?.platform ?? process.platform;
|
|
1327
|
+
const groupExists = options?.processGroupExists ?? processGroupExists;
|
|
1328
|
+
const readDirectory = options?.readDirectory ?? readdirSync;
|
|
1329
|
+
const readStat = options?.readStat ?? readFileSync;
|
|
1330
|
+
const observationTime = options?.now?.() ?? performance.now();
|
|
1331
|
+
const warn = options?.warn ?? ((message) => harperLogger.warn(message));
|
|
1332
|
+
if (!groupExists(processGroupId)) {
|
|
1333
|
+
clearProcessGroupLivenessState(processGroupId);
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
const leaderState = processGroupLeaderState(processGroupId, platform, readStat);
|
|
1337
|
+
if (leaderState.state === 'alive')
|
|
1338
|
+
return keepProcessGroupAlive(processGroupId, 'the process-group leader is still alive', observationTime, warn);
|
|
1339
|
+
if (leaderState.state === 'unknown')
|
|
1340
|
+
return keepProcessGroupAlive(processGroupId, leaderState.reason, observationTime, warn);
|
|
1341
|
+
const scanTime = observationTime;
|
|
1342
|
+
const lastScan = zombieGroupScanTimes.get(processGroupId);
|
|
1343
|
+
if (lastScan !== undefined && scanTime >= lastScan && scanTime - lastScan < ZOMBIE_GROUP_MEMBER_SCAN_INTERVAL_MS) {
|
|
1344
|
+
const reason = processGroupLivenessStates.get(processGroupId)?.reason ?? 'the previous Linux scan is still current';
|
|
1345
|
+
return keepProcessGroupAlive(processGroupId, reason, observationTime, warn);
|
|
1346
|
+
}
|
|
1347
|
+
zombieGroupScanTimes.set(processGroupId, scanTime);
|
|
1348
|
+
let scanResult = scanLinuxProcessGroup(processGroupId, readDirectory, readStat);
|
|
1349
|
+
if (scanResult.isAlive !== false)
|
|
1350
|
+
return keepProcessGroupAlive(processGroupId, scanResult.reason, observationTime, warn);
|
|
1351
|
+
// A second snapshot catches a member omitted after forking inside the first readdir/stat window.
|
|
1352
|
+
// It narrows rather than closes the race because the second synchronous pass has the same gap.
|
|
1353
|
+
scanResult = scanLinuxProcessGroup(processGroupId, readDirectory, readStat);
|
|
1354
|
+
if (scanResult.isAlive !== false)
|
|
1355
|
+
return keepProcessGroupAlive(processGroupId, scanResult.reason, observationTime, warn);
|
|
1356
|
+
clearProcessGroupLivenessState(processGroupId);
|
|
1357
|
+
return false;
|
|
1358
|
+
}
|
|
1359
|
+
function processGroupIsAlive(processGroupId) {
|
|
1360
|
+
return isProcessGroupAlive(processGroupId);
|
|
984
1361
|
}
|
|
985
1362
|
async function waitForProcessGroupExit(processGroupId) {
|
|
986
1363
|
while (processGroupIsAlive(processGroupId))
|
|
@@ -1054,6 +1431,7 @@ function addProcessGroup(ownerThreadId, processGroupId) {
|
|
|
1054
1431
|
processGroups.add(processGroupId);
|
|
1055
1432
|
}
|
|
1056
1433
|
function removeProcessGroup(ownerThreadId, processGroupId) {
|
|
1434
|
+
clearProcessGroupLivenessState(processGroupId);
|
|
1057
1435
|
const processGroups = processGroupsByThread.get(ownerThreadId);
|
|
1058
1436
|
if (!processGroups)
|
|
1059
1437
|
return;
|
|
@@ -1107,6 +1485,39 @@ function unregisterProcessGroup(processGroupId) {
|
|
|
1107
1485
|
else
|
|
1108
1486
|
parentPort?.postMessage({ type: UNREGISTER_PROCESS_GROUP, processGroupId });
|
|
1109
1487
|
}
|
|
1488
|
+
class ProcessGroupTerminationUnconfirmedError extends Error {
|
|
1489
|
+
code = 'ERR_PROCESS_GROUP_TERMINATION_UNCONFIRMED';
|
|
1490
|
+
constructor(ownerThreadId, timeoutMs) {
|
|
1491
|
+
super(`Thread ${ownerThreadId}'s process-group termination could not be confirmed after ${timeoutMs}ms`);
|
|
1492
|
+
this.name = 'ProcessGroupTerminationUnconfirmedError';
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
// Bounds awaitProcessGroupTermination for isThreadRunning below. Throws rather than resolving to
|
|
1496
|
+
// "not running": componentPreparationLock's ownerIsAlive/ownerLivenessConfirmed already treat a
|
|
1497
|
+
// throwing isOwnerAlive as "can't confirm — don't steal the claim, don't renew the deadline", so
|
|
1498
|
+
// the lock's own bounded wait is what eventually fails the waiter.
|
|
1499
|
+
async function awaitConfirmedProcessGroupTermination(ownerThreadId) {
|
|
1500
|
+
const abortController = new AbortController();
|
|
1501
|
+
let timedOut = false;
|
|
1502
|
+
const timer = setTimeout(() => {
|
|
1503
|
+
timedOut = true;
|
|
1504
|
+
abortController.abort();
|
|
1505
|
+
}, THREAD_RUNNING_TERMINATION_BACKSTOP_MS);
|
|
1506
|
+
timer.unref?.();
|
|
1507
|
+
try {
|
|
1508
|
+
await Promise.race([
|
|
1509
|
+
awaitProcessGroupTermination(ownerThreadId, abortController.signal),
|
|
1510
|
+
new Promise((resolve) => abortController.signal.addEventListener('abort', resolve, { once: true })),
|
|
1511
|
+
]);
|
|
1512
|
+
}
|
|
1513
|
+
finally {
|
|
1514
|
+
clearTimeout(timer);
|
|
1515
|
+
}
|
|
1516
|
+
if (timedOut) {
|
|
1517
|
+
harperLogger.warn(`Thread ${ownerThreadId}'s process-group termination could not be confirmed after ${THREAD_RUNNING_TERMINATION_BACKSTOP_MS}ms`);
|
|
1518
|
+
throw new ProcessGroupTerminationUnconfirmedError(ownerThreadId, THREAD_RUNNING_TERMINATION_BACKSTOP_MS);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1110
1521
|
async function isThreadRunning(ownerThreadId, timeoutMs = THREAD_INFO_REQUEST_TIMEOUT_MS) {
|
|
1111
1522
|
if (ownerThreadId === threadId || ownerThreadId === 0)
|
|
1112
1523
|
return true;
|
|
@@ -1114,7 +1525,7 @@ async function isThreadRunning(ownerThreadId, timeoutMs = THREAD_INFO_REQUEST_TI
|
|
|
1114
1525
|
return true;
|
|
1115
1526
|
// The thread itself is gone, but it may still own process groups whose forced termination is
|
|
1116
1527
|
// in flight — wait for that to be confirmed before reporting the owner as reclaimable.
|
|
1117
|
-
await
|
|
1528
|
+
await awaitConfirmedProcessGroupTermination(ownerThreadId);
|
|
1118
1529
|
return false;
|
|
1119
1530
|
}
|
|
1120
1531
|
if (isMainThread) {
|
|
@@ -1123,6 +1534,14 @@ if (isMainThread) {
|
|
|
1123
1534
|
terminateProcessGroupsForThread(ownerThreadId);
|
|
1124
1535
|
});
|
|
1125
1536
|
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Whether a thread has already been reported dead. Sync, unlike `isThreadRunning`, because it only
|
|
1539
|
+
* reads the tombstone `notifyThreadExit` records below — callers on the exit path need an answer
|
|
1540
|
+
* without awaiting process-group confirmation.
|
|
1541
|
+
*/
|
|
1542
|
+
function hasThreadExited(threadId) {
|
|
1543
|
+
return notifiedDeadThreadIds.has(threadId);
|
|
1544
|
+
}
|
|
1126
1545
|
function notifyThreadExit(deadThreadId) {
|
|
1127
1546
|
if (deadThreadId == null || notifiedDeadThreadIds.has(deadThreadId))
|
|
1128
1547
|
return;
|
|
@@ -1246,25 +1665,51 @@ if (isMainThread) {
|
|
|
1246
1665
|
const watchDir = async (dir, beforeRestartCallback) => {
|
|
1247
1666
|
if (beforeRestartCallback)
|
|
1248
1667
|
beforeRestart = beforeRestartCallback;
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1668
|
+
const watchTarget = resolveWatchTarget(dir);
|
|
1669
|
+
let usingPolling = watchTarget.mustPoll;
|
|
1670
|
+
let liveWatcher;
|
|
1671
|
+
const openWatcher = () => {
|
|
1672
|
+
const opened = (liveWatcher = guardedWatch(watchTarget.path, {
|
|
1673
|
+
persistent: false,
|
|
1674
|
+
...(usingPolling ? DIRECTORY_POLLING_FALLBACK_OPTIONS : {}),
|
|
1675
|
+
ignored: (path) => {
|
|
1676
|
+
return ignoredPaths.some((ignoredPath) => path.includes(ignoredPath));
|
|
1677
|
+
},
|
|
1678
|
+
}));
|
|
1679
|
+
opened
|
|
1680
|
+
// This runs on the thread that owns every worker, and chokidar emits 'error' unguarded for
|
|
1681
|
+
// anything but ENOENT/ENOTDIR.
|
|
1682
|
+
.on('error', (error) => {
|
|
1683
|
+
if (claimLostNativeWatchError(error))
|
|
1684
|
+
return;
|
|
1685
|
+
if (isWatcherExhaustionError(error)) {
|
|
1686
|
+
if (usingPolling || liveWatcher !== opened)
|
|
1687
|
+
return;
|
|
1688
|
+
warnWatcherFallback(dir);
|
|
1689
|
+
usingPolling = true;
|
|
1690
|
+
Promise.resolve()
|
|
1691
|
+
.then(() => opened.close())
|
|
1692
|
+
.catch(() => { })
|
|
1693
|
+
.then(openWatcher)
|
|
1694
|
+
.catch((reopenError) => console.error(`Could not reopen the ${dir} component-reload watch on polling:`, reopenError));
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
console.error(`Error watching ${dir} for component reloads:`, error);
|
|
1698
|
+
})
|
|
1699
|
+
.on('change', (path) => {
|
|
1700
|
+
changedFiles.add(path);
|
|
1701
|
+
if (queuedRestart)
|
|
1702
|
+
clearTimeout(queuedRestart);
|
|
1703
|
+
queuedRestart = setTimeout(async () => {
|
|
1704
|
+
if (beforeRestart)
|
|
1705
|
+
await beforeRestart();
|
|
1706
|
+
await restartWorkers();
|
|
1707
|
+
console.log('Reloaded Harper components, changed files:', Array.from(changedFiles));
|
|
1708
|
+
changedFiles.clear();
|
|
1709
|
+
}, 100);
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1712
|
+
openWatcher();
|
|
1268
1713
|
};
|
|
1269
1714
|
module.exports.watchDir = watchDir;
|
|
1270
1715
|
if (process.env.WATCH_DIR)
|