@sentio/runtime 2.58.0-rc.7 → 2.58.0
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/lib/chunk-LHDBKJ2B.js +116 -0
- package/lib/{chunk-NLEBXJPP.js.map → chunk-LHDBKJ2B.js.map} +1 -1
- package/lib/chunk-NEX6GJVW.js +26 -0
- package/lib/{chunk-ZUTD563J.js.map → chunk-NEX6GJVW.js.map} +1 -1
- package/lib/chunk-QVIDLAYP.js +38 -0
- package/lib/{chunk-BPGFX5S5.js.map → chunk-QVIDLAYP.js.map} +1 -1
- package/lib/chunk-WHWNPZZ3.js +3 -0
- package/lib/{chunk-6XHWJ2VS.js.map → chunk-WHWNPZZ3.js.map} +1 -1
- package/lib/index.js +1 -70
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +21 -26566
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.js +2 -128
- package/lib/service-worker.js.map +1 -1
- package/lib/test-processor.test.js.map +1 -1
- package/package.json +1 -1
- package/src/processor-runner.ts +37 -11
- package/lib/chunk-6XHWJ2VS.js +0 -92
- package/lib/chunk-BPGFX5S5.js +0 -10975
- package/lib/chunk-NLEBXJPP.js +0 -59726
- package/lib/chunk-ZUTD563J.js +0 -23006
package/lib/service-worker.js
CHANGED
@@ -1,130 +1,4 @@
|
|
1
1
|
import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
|
2
|
-
import {
|
3
|
-
|
4
|
-
} from "./chunk-BPGFX5S5.js";
|
5
|
-
import {
|
6
|
-
AbstractStoreContext,
|
7
|
-
configureEndpoints,
|
8
|
-
errorString,
|
9
|
-
freezeGlobalConfig,
|
10
|
-
recordRuntimeInfo,
|
11
|
-
require_lib3 as require_lib,
|
12
|
-
require_lib4 as require_lib2
|
13
|
-
} from "./chunk-NLEBXJPP.js";
|
14
|
-
import {
|
15
|
-
PluginManager,
|
16
|
-
ProcessConfigResponse,
|
17
|
-
__toESM
|
18
|
-
} from "./chunk-ZUTD563J.js";
|
19
|
-
|
20
|
-
// src/service-worker.ts
|
21
|
-
var import_nice_grpc = __toESM(require_lib(), 1);
|
22
|
-
var import_nice_grpc_error_details = __toESM(require_lib2(), 1);
|
23
|
-
import { BroadcastChannel, threadId } from "worker_threads";
|
24
|
-
import { Piscina } from "piscina";
|
25
|
-
var started = false;
|
26
|
-
var unhandled;
|
27
|
-
process.on("uncaughtException", (err) => {
|
28
|
-
console.error("Uncaught Exception, please checking if await is properly used", err);
|
29
|
-
unhandled = err;
|
30
|
-
}).on("unhandledRejection", (reason, p) => {
|
31
|
-
if (reason?.message.startsWith('invalid ENS name (disallowed character: "*"')) {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
console.error("Unhandled Rejection, please checking if await is properly", reason);
|
35
|
-
unhandled = reason;
|
36
|
-
});
|
37
|
-
async function getConfig(request, context) {
|
38
|
-
if (!started) {
|
39
|
-
throw new import_nice_grpc.ServerError(import_nice_grpc.Status.UNAVAILABLE, "Service Not started.");
|
40
|
-
}
|
41
|
-
const newConfig = ProcessConfigResponse.fromPartial({});
|
42
|
-
await PluginManager.INSTANCE.configure(newConfig);
|
43
|
-
return newConfig;
|
44
|
-
}
|
45
|
-
var loader = async (options) => {
|
46
|
-
if (options.target) {
|
47
|
-
const m = await import(options.target);
|
48
|
-
console.debug("Module loaded, path:", options.target, "module:", m);
|
49
|
-
return m;
|
50
|
-
}
|
51
|
-
};
|
52
|
-
var configureChannel = new BroadcastChannel("configure_channel");
|
53
|
-
configureChannel.onmessage = (request) => {
|
54
|
-
getConfig(request);
|
55
|
-
};
|
56
|
-
async function start(request, options) {
|
57
|
-
if (started) {
|
58
|
-
return {};
|
59
|
-
}
|
60
|
-
freezeGlobalConfig();
|
61
|
-
try {
|
62
|
-
await loader(options);
|
63
|
-
} catch (e) {
|
64
|
-
throw new import_nice_grpc.ServerError(import_nice_grpc.Status.INVALID_ARGUMENT, "Failed to load processor: " + errorString(e));
|
65
|
-
}
|
66
|
-
await PluginManager.INSTANCE.start(request);
|
67
|
-
started = true;
|
68
|
-
return {};
|
69
|
-
}
|
70
|
-
async function service_worker_default({
|
71
|
-
request,
|
72
|
-
processId,
|
73
|
-
workerPort
|
74
|
-
}) {
|
75
|
-
const { startRequest, configRequest, options } = Piscina.workerData;
|
76
|
-
if (!started) {
|
77
|
-
const logLevel = process.env["LOG_LEVEL"]?.toUpperCase();
|
78
|
-
setupLogger(options["log-format"] === "json", logLevel === "debug" ? true : options.debug, threadId);
|
79
|
-
configureEndpoints(options);
|
80
|
-
if (startRequest) {
|
81
|
-
await start(startRequest, options);
|
82
|
-
console.debug("worker started, template instance:", startRequest.templateInstances?.length);
|
83
|
-
}
|
84
|
-
if (configRequest) {
|
85
|
-
await getConfig(configRequest);
|
86
|
-
console.debug("worker configured");
|
87
|
-
}
|
88
|
-
}
|
89
|
-
if (unhandled) {
|
90
|
-
const err = unhandled;
|
91
|
-
unhandled = void 0;
|
92
|
-
throw new import_nice_grpc_error_details.RichServerError(
|
93
|
-
import_nice_grpc.Status.UNAVAILABLE,
|
94
|
-
"Unhandled exception/rejection in previous request: " + errorString(err),
|
95
|
-
[
|
96
|
-
import_nice_grpc_error_details.DebugInfo.fromPartial({
|
97
|
-
detail: err.message,
|
98
|
-
stackEntries: err.stack?.split("\n")
|
99
|
-
})
|
100
|
-
]
|
101
|
-
);
|
102
|
-
}
|
103
|
-
const result = await PluginManager.INSTANCE.processBinding(
|
104
|
-
request,
|
105
|
-
void 0,
|
106
|
-
workerPort ? new WorkerStoreContext(workerPort, processId) : void 0
|
107
|
-
);
|
108
|
-
recordRuntimeInfo(result, request.handlerType);
|
109
|
-
return result;
|
110
|
-
}
|
111
|
-
var WorkerStoreContext = class extends AbstractStoreContext {
|
112
|
-
constructor(port, processId) {
|
113
|
-
super(processId);
|
114
|
-
this.port = port;
|
115
|
-
this.port.on("message", (resp) => {
|
116
|
-
this.result(resp);
|
117
|
-
});
|
118
|
-
this.port.on("close", () => {
|
119
|
-
this.close();
|
120
|
-
});
|
121
|
-
}
|
122
|
-
doSend(req) {
|
123
|
-
this.port.postMessage(req);
|
124
|
-
}
|
125
|
-
};
|
126
|
-
import("node:process").then((p) => p.stdout.write(""));
|
127
|
-
export {
|
128
|
-
service_worker_default as default
|
129
|
-
};
|
2
|
+
import{a as R}from"./chunk-QVIDLAYP.js";import{T as C,_ as P,b as d,i as w,o as y,p as A,r as E}from"./chunk-LHDBKJ2B.js";import{e as m,q as h,u}from"./chunk-NEX6GJVW.js";var o=m(y(),1);var p=m(A(),1);import{BroadcastChannel as I,threadId as N}from"worker_threads";import{Piscina as b}from"piscina";var l=!1,a;process.on("uncaughtException",e=>{console.error("Uncaught Exception, please checking if await is properly used",e),a=e}).on("unhandledRejection",(e,r)=>{e?.message.startsWith('invalid ENS name (disallowed character: "*"')||(console.error("Unhandled Rejection, please checking if await is properly",e),a=e)});async function S(e,r){if(!l)throw new o.ServerError(o.Status.UNAVAILABLE,"Service Not started.");let t=h.fromPartial({});return await u.INSTANCE.configure(t),t}var L=async e=>{if(e.target){let r=await import(e.target);return console.debug("Module loaded, path:",e.target,"module:",r),r}},q=new I("configure_channel");q.onmessage=e=>{S(e)};async function D(e,r){if(l)return{};E();try{await L(r)}catch(t){throw new o.ServerError(o.Status.INVALID_ARGUMENT,"Failed to load processor: "+d(t))}return await u.INSTANCE.start(e),l=!0,{}}async function X({request:e,processId:r,workerPort:t}){let{startRequest:n,configRequest:i,options:c}=b.workerData;if(!l){let s=process.env.LOG_LEVEL?.toUpperCase();R(c["log-format"]==="json",s==="debug"?!0:c.debug,N),w(c),n&&(await D(n,c),console.debug("worker started, template instance:",n.templateInstances?.length)),i&&(await S(i),console.debug("worker configured"))}if(a){let s=a;throw a=void 0,new p.RichServerError(o.Status.UNAVAILABLE,"Unhandled exception/rejection in previous request: "+d(s),[p.DebugInfo.fromPartial({detail:s.message,stackEntries:s.stack?.split(`
|
3
|
+
`)})])}let g=await u.INSTANCE.processBinding(e,void 0,t?new f(t,r):void 0);return P(g,e.handlerType),g}var f=class extends C{constructor(t,n){super(n);this.port=t;this.port.on("message",i=>{this.result(i)}),this.port.on("close",()=>{this.close()})}doSend(t){this.port.postMessage(t)}};import("node:process").then(e=>e.stdout.write(""));export{X as default};
|
130
4
|
//# sourceMappingURL=service-worker.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {\n DataBinding,\n DBResponse,\n DeepPartial,\n Empty,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessStreamResponse,\n StartRequest\n} from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { PluginManager } from './plugin.js'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { recordRuntimeInfo } from './service.js'\nimport { BroadcastChannel, MessagePort, threadId } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\nimport { setupLogger } from './logger.js'\nimport { AbstractStoreContext } from './db-context.js'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n\nasync function getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse> {\n if (!started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const newConfig = ProcessConfigResponse.fromPartial({})\n await PluginManager.INSTANCE.configure(newConfig)\n return newConfig\n}\n\nconst loader = async (options: any) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, 'module:', m)\n return m\n }\n}\n\nconst configureChannel = new BroadcastChannel('configure_channel')\nconfigureChannel.onmessage = (request: ProcessConfigRequest) => {\n getConfig(request)\n}\n\nasync function start(request: StartRequest, options: any): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n await loader(options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await PluginManager.INSTANCE.start(request)\n started = true\n return {}\n}\n\nexport default async function ({\n request,\n processId,\n workerPort\n}: {\n request: DataBinding\n processId: number\n workerPort?: MessagePort\n}) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n const logLevel = process.env['LOG_LEVEL']?.toUpperCase()\n setupLogger(options['log-format'] === 'json', logLevel === 'debug' ? true : options.debug, threadId)\n\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker started, template instance:', startRequest.templateInstances?.length)\n }\n\n if (configRequest) {\n await getConfig(configRequest)\n console.debug('worker configured')\n }\n }\n\n if (unhandled) {\n const err = unhandled\n unhandled = undefined\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(err),\n [\n DebugInfo.fromPartial({\n detail: err.message,\n stackEntries: err.stack?.split('\\n')\n })\n ]\n )\n }\n\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined,\n workerPort ? new WorkerStoreContext(workerPort, processId) : undefined\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n}\n\nclass WorkerStoreContext extends AbstractStoreContext {\n constructor(\n readonly port: MessagePort,\n processId: number\n ) {\n super(processId)\n this.port.on('message', (resp: DBResponse) => {\n this.result(resp)\n })\n this.port.on('close', () => {\n this.close()\n })\n }\n\n doSend(req: DeepPartial<ProcessStreamResponse>): void {\n this.port.postMessage(req)\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"
|
1
|
+
{"version":3,"sources":["../src/service-worker.ts"],"sourcesContent":["import {\n DataBinding,\n DBResponse,\n DeepPartial,\n Empty,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessStreamResponse,\n StartRequest\n} from '@sentio/protos'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { PluginManager } from './plugin.js'\nimport { errorString } from './utils.js'\nimport { freezeGlobalConfig } from './global-config.js'\nimport { DebugInfo, RichServerError } from 'nice-grpc-error-details'\nimport { recordRuntimeInfo } from './service.js'\nimport { BroadcastChannel, MessagePort, threadId } from 'worker_threads'\nimport { Piscina } from 'piscina'\nimport { configureEndpoints } from './endpoints.js'\nimport { setupLogger } from './logger.js'\nimport { AbstractStoreContext } from './db-context.js'\n\nlet started = false\n\nlet unhandled: Error | undefined\n\nprocess\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n unhandled = err\n })\n .on('unhandledRejection', (reason, p) => {\n // @ts-ignore ignore invalid ens error\n if (reason?.message.startsWith('invalid ENS name (disallowed character: \"*\"')) {\n return\n }\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n unhandled = reason as Error\n // shutdownServers(1)\n })\n\nasync function getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse> {\n if (!started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const newConfig = ProcessConfigResponse.fromPartial({})\n await PluginManager.INSTANCE.configure(newConfig)\n return newConfig\n}\n\nconst loader = async (options: any) => {\n if (options.target) {\n const m = await import(options.target)\n console.debug('Module loaded, path:', options.target, 'module:', m)\n return m\n }\n}\n\nconst configureChannel = new BroadcastChannel('configure_channel')\nconfigureChannel.onmessage = (request: ProcessConfigRequest) => {\n getConfig(request)\n}\n\nasync function start(request: StartRequest, options: any): Promise<Empty> {\n if (started) {\n return {}\n }\n freezeGlobalConfig()\n\n try {\n await loader(options)\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await PluginManager.INSTANCE.start(request)\n started = true\n return {}\n}\n\nexport default async function ({\n request,\n processId,\n workerPort\n}: {\n request: DataBinding\n processId: number\n workerPort?: MessagePort\n}) {\n const { startRequest, configRequest, options } = Piscina.workerData\n if (!started) {\n const logLevel = process.env['LOG_LEVEL']?.toUpperCase()\n setupLogger(options['log-format'] === 'json', logLevel === 'debug' ? true : options.debug, threadId)\n\n configureEndpoints(options)\n\n if (startRequest) {\n await start(startRequest, options)\n console.debug('worker started, template instance:', startRequest.templateInstances?.length)\n }\n\n if (configRequest) {\n await getConfig(configRequest)\n console.debug('worker configured')\n }\n }\n\n if (unhandled) {\n const err = unhandled\n unhandled = undefined\n throw new RichServerError(\n Status.UNAVAILABLE,\n 'Unhandled exception/rejection in previous request: ' + errorString(err),\n [\n DebugInfo.fromPartial({\n detail: err.message,\n stackEntries: err.stack?.split('\\n')\n })\n ]\n )\n }\n\n const result = await PluginManager.INSTANCE.processBinding(\n request,\n undefined,\n workerPort ? new WorkerStoreContext(workerPort, processId) : undefined\n )\n recordRuntimeInfo(result, request.handlerType)\n return result\n}\n\nclass WorkerStoreContext extends AbstractStoreContext {\n constructor(\n readonly port: MessagePort,\n processId: number\n ) {\n super(processId)\n this.port.on('message', (resp: DBResponse) => {\n this.result(resp)\n })\n this.port.on('close', () => {\n this.close()\n })\n }\n\n doSend(req: DeepPartial<ProcessStreamResponse>): void {\n this.port.postMessage(req)\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"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","names":["import_nice_grpc","import_nice_grpc_error_details","BroadcastChannel","threadId","Piscina","started","unhandled","err","reason","p","getConfig","request","context","newConfig","ProcessConfigResponse","PluginManager","loader","options","m","configureChannel","BroadcastChannel","start","freezeGlobalConfig","e","errorString","service_worker_default","processId","workerPort","startRequest","configRequest","Piscina","logLevel","setupLogger","threadId","configureEndpoints","result","WorkerStoreContext","recordRuntimeInfo","AbstractStoreContext","port","resp","req"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":"
|
1
|
+
{"version":3,"sources":["../src/test-processor.test.ts"],"sourcesContent":["import { Plugin, PluginManager } from './plugin.js'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n const dbContext = PluginManager.INSTANCE.dbContextLocalStorage.getStore()\n if (dbContext) {\n await dbContext.sendRequest({\n get: {\n entity: 'Test',\n id: '1'\n }\n })\n }\n\n return ProcessResult.fromPartial({\n states: {\n configUpdated: true\n }\n })\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.ETH_LOG]\n}\n\nPluginManager.INSTANCE.plugins = []\nPluginManager.INSTANCE.register(new TestPlugin())\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";sDAGA,IAAMA,EAAN,cAAyBC,CAAO,CAC9B,MAAM,eAAeC,EAA8C,CACjE,IAAMC,EAAYC,EAAc,SAAS,sBAAsB,SAAS,EACxE,OAAID,GACF,MAAMA,EAAU,YAAY,CAC1B,IAAK,CACH,OAAQ,OACR,GAAI,GACN,CACF,CAAC,EAGIE,EAAc,YAAY,CAC/B,OAAQ,CACN,cAAe,EACjB,CACF,CAAC,CACH,CACA,kBAAoB,IAAyC,CAC/D,EAEAD,EAAc,SAAS,QAAU,CAAC,EAClCA,EAAc,SAAS,SAAS,IAAIJ,CAAY,EAC/C,OAAO,cAAc,EAAE,KAAMM,GAAMA,EAAE,OAAO,MAAM,EAAE,CAAC","names":["TestPlugin","Plugin","request","dbContext","PluginManager","ProcessResult","p"]}
|
package/package.json
CHANGED
package/src/processor-runner.ts
CHANGED
@@ -102,6 +102,7 @@ if (options['start-action-server']) {
|
|
102
102
|
}
|
103
103
|
|
104
104
|
const metricsPort = 4040
|
105
|
+
|
105
106
|
const httpServer = http
|
106
107
|
.createServer(async function (req, res) {
|
107
108
|
if (req.url) {
|
@@ -115,17 +116,7 @@ const httpServer = http
|
|
115
116
|
case '/heap': {
|
116
117
|
try {
|
117
118
|
const file = '/tmp/' + Date.now() + '.heapsnapshot'
|
118
|
-
|
119
|
-
|
120
|
-
const fd = fs.openSync(file, 'w')
|
121
|
-
session.connect()
|
122
|
-
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
|
123
|
-
fs.writeSync(fd, m.params.chunk)
|
124
|
-
})
|
125
|
-
|
126
|
-
await session.post('HeapProfiler.takeHeapSnapshot')
|
127
|
-
session.disconnect()
|
128
|
-
fs.closeSync(fd)
|
119
|
+
await dumpHeap(file)
|
129
120
|
// send the file
|
130
121
|
const readStream = fs.createReadStream(file)
|
131
122
|
res.writeHead(200, { 'Content-Type': 'application/json' })
|
@@ -192,6 +183,41 @@ process
|
|
192
183
|
// shutdownServers(1)
|
193
184
|
})
|
194
185
|
|
186
|
+
if (process.env['OOM_DUMP_MEMORY_SIZE_GB']) {
|
187
|
+
let dumping = false
|
188
|
+
const memorySize = parseInt(process.env['OOM_DUMP_MEMORY_SIZE_GB'], 10)
|
189
|
+
console.log('heap dumping is enabled, limit set to ', memorySize, 'gb')
|
190
|
+
setInterval(async () => {
|
191
|
+
const mem = process.memoryUsage()
|
192
|
+
// if memory usage is greater this size, dump heap and exit
|
193
|
+
if (mem.heapTotal > memorySize * 1024 * 1024 * 1024 && !dumping) {
|
194
|
+
const file = '/tmp/' + Date.now() + '.heapsnapshot'
|
195
|
+
dumping = true
|
196
|
+
await dumpHeap(file)
|
197
|
+
// force exit and keep pod running
|
198
|
+
process.exit(11)
|
199
|
+
}
|
200
|
+
}, 1000 * 60)
|
201
|
+
}
|
202
|
+
|
203
|
+
async function dumpHeap(file: string) {
|
204
|
+
console.log('Heap dumping to', file)
|
205
|
+
const session = new Session()
|
206
|
+
const fd = fs.openSync(file, 'w')
|
207
|
+
try {
|
208
|
+
session.connect()
|
209
|
+
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
|
210
|
+
fs.writeSync(fd, m.params.chunk)
|
211
|
+
})
|
212
|
+
|
213
|
+
await session.post('HeapProfiler.takeHeapSnapshot')
|
214
|
+
console.log('Heap dumped to', file)
|
215
|
+
} finally {
|
216
|
+
session.disconnect()
|
217
|
+
fs.closeSync(fd)
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
195
221
|
function shutdownServers(exitCode: number) {
|
196
222
|
server?.forceShutdown()
|
197
223
|
console.log('RPC server shut down')
|
package/lib/chunk-6XHWJ2VS.js
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
|
2
|
-
|
3
|
-
// src/state.ts
|
4
|
-
import { isMainThread, parentPort, threadId } from "node:worker_threads";
|
5
|
-
var State = class _State {
|
6
|
-
stateMap = /* @__PURE__ */ new Map();
|
7
|
-
static INSTANCE = new _State();
|
8
|
-
static reset() {
|
9
|
-
_State.INSTANCE = new _State();
|
10
|
-
}
|
11
|
-
};
|
12
|
-
var StateStorage = class {
|
13
|
-
// TODO learn how to define single instance for all subclasses
|
14
|
-
constructor() {
|
15
|
-
}
|
16
|
-
key() {
|
17
|
-
return this.constructor.name;
|
18
|
-
}
|
19
|
-
getOrRegister() {
|
20
|
-
let metricState = State.INSTANCE.stateMap.get(this.key());
|
21
|
-
if (!metricState) {
|
22
|
-
metricState = this.initValue();
|
23
|
-
State.INSTANCE.stateMap.set(this.key(), metricState);
|
24
|
-
}
|
25
|
-
return metricState;
|
26
|
-
}
|
27
|
-
unregister() {
|
28
|
-
const value = State.INSTANCE.stateMap.get(this.key());
|
29
|
-
State.INSTANCE.stateMap.delete(this.key());
|
30
|
-
return value;
|
31
|
-
}
|
32
|
-
};
|
33
|
-
var MapStateStorage = class extends StateStorage {
|
34
|
-
initValue() {
|
35
|
-
return /* @__PURE__ */ new Map();
|
36
|
-
}
|
37
|
-
getValue(key) {
|
38
|
-
const m = this.getOrRegister();
|
39
|
-
return m.get(key);
|
40
|
-
}
|
41
|
-
getValues() {
|
42
|
-
const m = this.getOrRegister();
|
43
|
-
return Array.from(m.values());
|
44
|
-
}
|
45
|
-
getOrSetValue(key, value) {
|
46
|
-
const m = this.getOrRegister();
|
47
|
-
const oldValue = m.get(key);
|
48
|
-
if (oldValue) {
|
49
|
-
if (oldValue !== value) {
|
50
|
-
console.warn(key, "has been registered twice, use the previous one");
|
51
|
-
}
|
52
|
-
return oldValue;
|
53
|
-
}
|
54
|
-
m.set(key, value);
|
55
|
-
return value;
|
56
|
-
}
|
57
|
-
};
|
58
|
-
var ListStateStorage = class extends StateStorage {
|
59
|
-
initValue() {
|
60
|
-
return [];
|
61
|
-
}
|
62
|
-
getValues() {
|
63
|
-
return this.getOrRegister();
|
64
|
-
}
|
65
|
-
addValue(value) {
|
66
|
-
const m = this.getOrRegister();
|
67
|
-
m.push(value);
|
68
|
-
return value;
|
69
|
-
}
|
70
|
-
};
|
71
|
-
var TemplateInstanceState = class _TemplateInstanceState extends ListStateStorage {
|
72
|
-
static INSTANCE = new _TemplateInstanceState();
|
73
|
-
constructor() {
|
74
|
-
super();
|
75
|
-
}
|
76
|
-
addValue(value) {
|
77
|
-
if (!isMainThread) {
|
78
|
-
parentPort?.postMessage({ event: "add_template_instance", value, from: threadId });
|
79
|
-
}
|
80
|
-
return super.addValue(value);
|
81
|
-
}
|
82
|
-
};
|
83
|
-
import("node:process").then((p) => p.stdout.write(""));
|
84
|
-
|
85
|
-
export {
|
86
|
-
State,
|
87
|
-
StateStorage,
|
88
|
-
MapStateStorage,
|
89
|
-
ListStateStorage,
|
90
|
-
TemplateInstanceState
|
91
|
-
};
|
92
|
-
//# sourceMappingURL=chunk-6XHWJ2VS.js.map
|