@platformatic/runtime 3.55.0 → 3.57.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/config.d.ts +43 -0
- package/index.d.ts +12 -1
- package/index.js +1 -0
- package/lib/config.js +3 -11
- package/lib/errors.js +4 -0
- package/lib/generator.js +39 -25
- package/lib/loopback-messaging.js +78 -0
- package/lib/management-api.js +3 -3
- package/lib/prom-server.js +30 -1
- package/lib/runtime.js +32 -8
- package/lib/utils.js +12 -3
- package/lib/worker/controller.js +44 -12
- package/lib/worker/health-signals.js +4 -2
- package/lib/worker/http-cache.js +5 -5
- package/lib/worker/interceptors.js +79 -19
- package/lib/worker/itc.js +16 -6
- package/lib/worker/main.js +22 -16
- package/lib/worker/management.js +3 -2
- package/lib/worker/messaging.js +23 -15
- package/lib/worker/shared-context.js +5 -3
- package/lib/worker/symbols.js +1 -2
- package/package.json +18 -17
- package/schema.json +126 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getITC, updateGlobals } from '@platformatic/globals'
|
|
1
2
|
import {
|
|
2
3
|
HealthSignalMustBeObjectError,
|
|
3
4
|
HealthSignalTypeMustBeStringError
|
|
@@ -60,7 +61,8 @@ export function initHealthSignalsApi (options = {}) {
|
|
|
60
61
|
isSending = false
|
|
61
62
|
try {
|
|
62
63
|
const signals = queue.getAll()
|
|
63
|
-
|
|
64
|
+
const itc = getITC()
|
|
65
|
+
await itc.send('sendHealthSignals', {
|
|
64
66
|
workerId,
|
|
65
67
|
signals
|
|
66
68
|
})
|
|
@@ -76,5 +78,5 @@ export function initHealthSignalsApi (options = {}) {
|
|
|
76
78
|
return promise
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
updateGlobals({ sendHealthSignal })
|
|
80
82
|
}
|
package/lib/worker/http-cache.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { getClientSpansAls, getITC } from '@platformatic/globals'
|
|
1
2
|
import { randomUUID } from 'node:crypto'
|
|
2
3
|
import { Readable, Writable } from 'node:stream'
|
|
3
4
|
import { interceptors } from 'undici'
|
|
4
|
-
import { kITC } from './symbols.js'
|
|
5
5
|
|
|
6
6
|
const kCacheIdHeader = Symbol('cacheIdHeader')
|
|
7
7
|
const CACHE_ID_HEADER = 'x-plt-http-cache-id'
|
|
@@ -28,7 +28,7 @@ export class RemoteCacheStore {
|
|
|
28
28
|
this.#logger.error(err, 'Error in onRequest http cache hook')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const itc =
|
|
31
|
+
const itc = getITC()
|
|
32
32
|
if (!itc) return
|
|
33
33
|
|
|
34
34
|
const sanitizedRequest = this.#sanitizeRequest(request)
|
|
@@ -68,7 +68,7 @@ export class RemoteCacheStore {
|
|
|
68
68
|
value.headers = { ...value.headers, [CACHE_ID_HEADER]: cacheEntryId }
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
const itc =
|
|
71
|
+
const itc = getITC()
|
|
72
72
|
if (!itc) throw new Error('Cannot write to cache without an ITC instance')
|
|
73
73
|
|
|
74
74
|
const acc = []
|
|
@@ -96,7 +96,7 @@ export class RemoteCacheStore {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
delete (request) {
|
|
99
|
-
const itc =
|
|
99
|
+
const itc = getITC()
|
|
100
100
|
if (!itc) throw new Error('Cannot delete from cache without an ITC instance')
|
|
101
101
|
|
|
102
102
|
request = this.#sanitizeRequest(request)
|
|
@@ -120,7 +120,7 @@ export function httpCacheInterceptor (interceptorOpts) {
|
|
|
120
120
|
|
|
121
121
|
// AsyncLocalStorage that contains a client http request span
|
|
122
122
|
// Exists only when the nodejs capability telemetry is enabled
|
|
123
|
-
const clientSpansAls =
|
|
123
|
+
const clientSpansAls = getClientSpansAls({ throwOnMissing: false })
|
|
124
124
|
|
|
125
125
|
return originalDispatch => {
|
|
126
126
|
const dispatch = (opts, handler) => {
|
|
@@ -1,14 +1,46 @@
|
|
|
1
|
-
import { mirrorGlobalDispatcherForBuiltinFetch } from '@platformatic/foundation'
|
|
1
|
+
import { getGlobalDispatcherFromKnownUndiciSymbols, mirrorGlobalDispatcherForBuiltinFetch } from '@platformatic/foundation'
|
|
2
|
+
import {
|
|
3
|
+
getInterceptors,
|
|
4
|
+
getLogger,
|
|
5
|
+
getOnHttpCacheHit,
|
|
6
|
+
getOnHttpCacheMiss,
|
|
7
|
+
getOnHttpCacheRequest
|
|
8
|
+
} from '@platformatic/globals'
|
|
2
9
|
import { createTelemetryThreadInterceptorHooks } from '@platformatic/telemetry'
|
|
3
10
|
import { createRequire } from 'node:module'
|
|
4
11
|
import { join } from 'node:path'
|
|
5
12
|
import { pathToFileURL } from 'node:url'
|
|
6
13
|
import { parentPort, workerData } from 'node:worker_threads'
|
|
7
|
-
import { Agent, Client, Pool
|
|
14
|
+
import { Agent, Client, Pool } from 'undici'
|
|
8
15
|
import { wire } from 'undici-thread-interceptor'
|
|
9
16
|
import { createChannelCreationHook } from '../policies.js'
|
|
10
17
|
import { RemoteCacheStore, httpCacheInterceptor } from './http-cache.js'
|
|
11
|
-
|
|
18
|
+
|
|
19
|
+
const kPlatformaticGlobalDispatcher = Symbol.for('platformatic.undici.globalDispatcher')
|
|
20
|
+
|
|
21
|
+
let composeRuntimeDispatcher
|
|
22
|
+
|
|
23
|
+
export function markAsPlatformaticDispatcher (dispatcher) {
|
|
24
|
+
Object.defineProperty(dispatcher, kPlatformaticGlobalDispatcher, {
|
|
25
|
+
value: true,
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function refreshGlobalDispatcher () {
|
|
32
|
+
if (!composeRuntimeDispatcher) {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const dispatcher = getGlobalDispatcherFromKnownUndiciSymbols()
|
|
37
|
+
if (!dispatcher || dispatcher[kPlatformaticGlobalDispatcher]) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
composeRuntimeDispatcher(dispatcher)
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
12
44
|
|
|
13
45
|
export async function setDispatcher (runtimeConfig) {
|
|
14
46
|
const threadDispatcher = createThreadInterceptor(runtimeConfig)
|
|
@@ -28,17 +60,39 @@ export async function setDispatcher (runtimeConfig) {
|
|
|
28
60
|
|
|
29
61
|
const dispatcherOpts = await getDispatcherOpts(runtimeConfig.undici)
|
|
30
62
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
63
|
+
function installDispatcher (baseDispatcher) {
|
|
64
|
+
const dispatcher = baseDispatcher.compose(
|
|
65
|
+
[threadInterceptor, ...userInterceptors, cacheInterceptor].filter(Boolean)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
markAsPlatformaticDispatcher(dispatcher)
|
|
69
|
+
mirrorGlobalDispatcherForBuiltinFetch(dispatcher, createLegacyDispatcher(dispatcher))
|
|
70
|
+
return dispatcher
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
composeRuntimeDispatcher = installDispatcher
|
|
74
|
+
installDispatcher(new Agent(dispatcherOpts))
|
|
36
75
|
|
|
37
76
|
return { threadDispatcher }
|
|
38
77
|
}
|
|
39
78
|
|
|
79
|
+
function createLegacyDispatcher (dispatcher) {
|
|
80
|
+
const legacyDispatcher = globalThis[Symbol.for('undici.globalDispatcher.1')]
|
|
81
|
+
const currentDispatcher = globalThis[Symbol.for('undici.globalDispatcher.2')]
|
|
82
|
+
|
|
83
|
+
if (legacyDispatcher && legacyDispatcher !== currentDispatcher && legacyDispatcher.constructor?.name === 'Dispatcher1Wrapper') {
|
|
84
|
+
try {
|
|
85
|
+
return new legacyDispatcher.constructor(dispatcher)
|
|
86
|
+
} catch {
|
|
87
|
+
return dispatcher
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return dispatcher
|
|
92
|
+
}
|
|
93
|
+
|
|
40
94
|
export async function updateUndiciInterceptors (undiciConfig) {
|
|
41
|
-
const updatableInterceptors =
|
|
95
|
+
const updatableInterceptors = getInterceptors()
|
|
42
96
|
if (!updatableInterceptors) return
|
|
43
97
|
|
|
44
98
|
if (Array.isArray(undiciConfig?.interceptors)) {
|
|
@@ -98,11 +152,7 @@ async function loadInterceptors (_require, interceptorsConfigs, key) {
|
|
|
98
152
|
}
|
|
99
153
|
|
|
100
154
|
async function loadInterceptor (_require, interceptorConfig, key) {
|
|
101
|
-
|
|
102
|
-
if (!updatableInterceptors) {
|
|
103
|
-
updatableInterceptors = {}
|
|
104
|
-
globalThis[kInterceptors] = updatableInterceptors
|
|
105
|
-
}
|
|
155
|
+
const updatableInterceptors = getInterceptors()
|
|
106
156
|
|
|
107
157
|
const { module, options } = interceptorConfig
|
|
108
158
|
|
|
@@ -199,24 +249,34 @@ function parseOrigins (origins) {
|
|
|
199
249
|
|
|
200
250
|
function createHttpCacheInterceptor (runtimeConfig) {
|
|
201
251
|
const httpCache = runtimeConfig.httpCache
|
|
252
|
+
|
|
202
253
|
const cacheInterceptor = httpCacheInterceptor({
|
|
203
254
|
store: new RemoteCacheStore({
|
|
204
255
|
onRequest: opts => {
|
|
205
|
-
|
|
256
|
+
const onHttpCacheRequest = getOnHttpCacheRequest({ throwOnMissing: false })
|
|
257
|
+
if (onHttpCacheRequest) {
|
|
258
|
+
onHttpCacheRequest(opts)
|
|
259
|
+
}
|
|
206
260
|
},
|
|
207
261
|
onCacheHit: opts => {
|
|
208
|
-
|
|
262
|
+
const onHttpCacheHit = getOnHttpCacheHit({ throwOnMissing: false })
|
|
263
|
+
if (onHttpCacheHit) {
|
|
264
|
+
onHttpCacheHit(opts)
|
|
265
|
+
}
|
|
209
266
|
},
|
|
210
267
|
onCacheMiss: opts => {
|
|
211
|
-
|
|
268
|
+
const onHttpCacheMiss = getOnHttpCacheMiss({ throwOnMissing: false })
|
|
269
|
+
if (onHttpCacheMiss) {
|
|
270
|
+
onHttpCacheMiss(opts)
|
|
271
|
+
}
|
|
212
272
|
},
|
|
213
|
-
logger:
|
|
273
|
+
logger: getLogger()
|
|
214
274
|
}),
|
|
215
275
|
methods: httpCache.methods ?? ['GET', 'HEAD'],
|
|
216
276
|
origins: parseOrigins(httpCache.origins),
|
|
217
277
|
cacheByDefault: httpCache.cacheByDefault,
|
|
218
278
|
type: httpCache.type,
|
|
219
|
-
logger:
|
|
279
|
+
logger: getLogger()
|
|
220
280
|
})
|
|
221
281
|
return cacheInterceptor
|
|
222
282
|
}
|
package/lib/worker/itc.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ensureLoggableError, executeInParallel, executeWithTimeout, kTimeout } from '@platformatic/foundation'
|
|
2
|
+
import { getEvents, getLogger, getMessaging, updateGlobals } from '@platformatic/globals'
|
|
2
3
|
import { initializeITCTelemetry, ITC } from '@platformatic/itc'
|
|
3
4
|
import { Unpromise } from '@watchable/unpromise'
|
|
4
5
|
import { once } from 'node:events'
|
|
@@ -150,10 +151,10 @@ export async function waitEventFromITC (worker, event) {
|
|
|
150
151
|
export async function setupITC (controller, application, dispatcher, sharedContext) {
|
|
151
152
|
await initializeITCTelemetry()
|
|
152
153
|
|
|
153
|
-
const logger =
|
|
154
|
+
const logger = getLogger()
|
|
154
155
|
const messaging = new MessagingITC(controller.applicationConfig.id, workerData.config, logger)
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
updateGlobals({
|
|
157
158
|
messaging: {
|
|
158
159
|
handle: messaging.handle.bind(messaging),
|
|
159
160
|
send: messaging.send.bind(messaging),
|
|
@@ -172,7 +173,8 @@ export async function setupITC (controller, application, dispatcher, sharedConte
|
|
|
172
173
|
await once(controller, 'start')
|
|
173
174
|
} else {
|
|
174
175
|
// This gives a chance to a capability to perform custom logic
|
|
175
|
-
|
|
176
|
+
const events = getEvents()
|
|
177
|
+
events.emit('start')
|
|
176
178
|
|
|
177
179
|
try {
|
|
178
180
|
await controller.start()
|
|
@@ -205,7 +207,8 @@ export async function setupITC (controller, application, dispatcher, sharedConte
|
|
|
205
207
|
|
|
206
208
|
if (force || status.startsWith('start')) {
|
|
207
209
|
// This gives a chance to a capability to perform custom logic
|
|
208
|
-
|
|
210
|
+
const events = getEvents()
|
|
211
|
+
events.emit('stop')
|
|
209
212
|
|
|
210
213
|
await controller.stop(force, dependents)
|
|
211
214
|
}
|
|
@@ -419,9 +422,16 @@ export async function setupITC (controller, application, dispatcher, sharedConte
|
|
|
419
422
|
// For service-based capabilities, expose the Fastify app
|
|
420
423
|
replServer.context.app = controller.capability?.getApplication?.()
|
|
421
424
|
replServer.context.capability = controller.capability
|
|
422
|
-
replServer.context.platformatic =
|
|
425
|
+
replServer.context.platformatic = {
|
|
426
|
+
capability: controller.capability,
|
|
427
|
+
config: controller.config,
|
|
428
|
+
events: getEvents(),
|
|
429
|
+
itc,
|
|
430
|
+
logger: getLogger(),
|
|
431
|
+
messaging: getMessaging()
|
|
432
|
+
}
|
|
423
433
|
replServer.context.config = controller.applicationConfig
|
|
424
|
-
replServer.context.logger =
|
|
434
|
+
replServer.context.logger = getLogger()
|
|
425
435
|
|
|
426
436
|
replServer.on('exit', () => {
|
|
427
437
|
port.postMessage({ type: 'exit' })
|
package/lib/worker/main.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getPrivateSymbol,
|
|
7
7
|
parseMemorySize
|
|
8
8
|
} from '@platformatic/foundation'
|
|
9
|
+
import { getITC, getLogger, updateGlobals } from '@platformatic/globals'
|
|
9
10
|
import { addPinoInstrumentation } from '@platformatic/telemetry'
|
|
10
11
|
import { Buffer } from 'node:buffer'
|
|
11
12
|
import { subscribe } from 'node:diagnostics_channel'
|
|
@@ -25,11 +26,12 @@ import { initHealthSignalsApi } from './health-signals.js'
|
|
|
25
26
|
import { setDispatcher } from './interceptors.js'
|
|
26
27
|
import { setupITC } from './itc.js'
|
|
27
28
|
import { SharedContext } from './shared-context.js'
|
|
28
|
-
import {
|
|
29
|
+
import { kStderrMarker } from './symbols.js'
|
|
29
30
|
|
|
30
31
|
function handlePreInitializationUnhandled (type, err) {
|
|
31
32
|
const label = `worker ${workerData.worker.index} of the application "${workerData.applicationConfig.id}"`
|
|
32
|
-
|
|
33
|
+
const logger = getLogger()
|
|
34
|
+
logger.error(
|
|
33
35
|
{ err: ensureLoggableError(err) },
|
|
34
36
|
`The ${label} threw an ${type} before initialization.`
|
|
35
37
|
)
|
|
@@ -38,7 +40,8 @@ function handlePreInitializationUnhandled (type, err) {
|
|
|
38
40
|
|
|
39
41
|
class ForwardingEventEmitter extends EventEmitter {
|
|
40
42
|
emitAndNotify (event, ...args) {
|
|
41
|
-
|
|
43
|
+
const itc = getITC()
|
|
44
|
+
itc.notify('event', { event, payload: args })
|
|
42
45
|
return this.emit(event, ...args)
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -201,8 +204,9 @@ async function main () {
|
|
|
201
204
|
const cleanup = setupHandlers()
|
|
202
205
|
|
|
203
206
|
installUndiciGlobals(globalThis)
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
updateGlobals({
|
|
208
|
+
runtimeId: threadId,
|
|
209
|
+
interceptors: {},
|
|
206
210
|
logger: createLogger(),
|
|
207
211
|
events: new ForwardingEventEmitter()
|
|
208
212
|
})
|
|
@@ -210,11 +214,11 @@ async function main () {
|
|
|
210
214
|
const runtimeConfig = workerData.config
|
|
211
215
|
const applicationConfig = workerData.applicationConfig
|
|
212
216
|
|
|
213
|
-
setupBufferPool(runtimeConfig, applicationConfig,
|
|
214
|
-
setupDefaultHighWaterMark(runtimeConfig, applicationConfig,
|
|
217
|
+
setupBufferPool(runtimeConfig, applicationConfig, getLogger())
|
|
218
|
+
setupDefaultHighWaterMark(runtimeConfig, applicationConfig, getLogger())
|
|
215
219
|
|
|
216
220
|
// Enable compile cache early before loading user modules
|
|
217
|
-
await setupCompileCache(runtimeConfig, applicationConfig,
|
|
221
|
+
await setupCompileCache(runtimeConfig, applicationConfig, getLogger())
|
|
218
222
|
|
|
219
223
|
await performPreloading(runtimeConfig, applicationConfig)
|
|
220
224
|
|
|
@@ -226,7 +230,8 @@ async function main () {
|
|
|
226
230
|
envfile = resolve(workerData.applicationConfig.path, '.env')
|
|
227
231
|
}
|
|
228
232
|
|
|
229
|
-
|
|
233
|
+
const logger = getLogger()
|
|
234
|
+
logger.debug({ envfile }, 'Loading envfile...')
|
|
230
235
|
|
|
231
236
|
try {
|
|
232
237
|
process.loadEnvFile(envfile)
|
|
@@ -301,15 +306,16 @@ async function main () {
|
|
|
301
306
|
|
|
302
307
|
const sharedContext = new SharedContext()
|
|
303
308
|
// Limit the amount of methods a user can call
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
309
|
+
updateGlobals({
|
|
310
|
+
sharedContext: {
|
|
311
|
+
get: () => sharedContext.get(),
|
|
312
|
+
update: (...args) => sharedContext.update(...args)
|
|
313
|
+
}
|
|
314
|
+
})
|
|
308
315
|
|
|
309
316
|
// Setup interaction with parent port
|
|
310
317
|
const itc = await setupITC(controller, applicationConfig, threadDispatcher, sharedContext)
|
|
311
|
-
|
|
312
|
-
globalThis.platformatic.itc = itc
|
|
318
|
+
updateGlobals({ itc })
|
|
313
319
|
|
|
314
320
|
// Setup management client for privileged applications
|
|
315
321
|
if (applicationConfig.management) {
|
|
@@ -322,7 +328,7 @@ async function main () {
|
|
|
322
328
|
const ops = typeof applicationConfig.management === 'object'
|
|
323
329
|
? applicationConfig.management.operations
|
|
324
330
|
: undefined
|
|
325
|
-
|
|
331
|
+
updateGlobals({ management: new ManagementClient(ops) })
|
|
326
332
|
}
|
|
327
333
|
}
|
|
328
334
|
|
package/lib/worker/management.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getITC } from '@platformatic/globals'
|
|
2
2
|
|
|
3
3
|
export class ManagementClient {
|
|
4
4
|
#allowedOperations
|
|
@@ -14,7 +14,8 @@ export class ManagementClient {
|
|
|
14
14
|
throw new Error(`Operation "${operation}" is not allowed`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const itc = getITC()
|
|
18
|
+
return itc.send('management:' + operation, data)
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
getRuntimeStatus () {
|
package/lib/worker/messaging.js
CHANGED
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
startOutgoingMessagingSpanSync,
|
|
11
11
|
traceIncomingMessagingHandler
|
|
12
12
|
} from '@platformatic/itc'
|
|
13
|
+
import { getITC } from '@platformatic/globals'
|
|
13
14
|
import { MessagingError } from '../errors.js'
|
|
14
15
|
import { RoundRobinMap } from './round-robin-map.js'
|
|
15
|
-
import {
|
|
16
|
+
import { kWorkersBroadcast } from './symbols.js'
|
|
16
17
|
|
|
17
18
|
const kPendingResponses = Symbol('plt.messaging.pendingResponses')
|
|
18
19
|
|
|
@@ -76,7 +77,7 @@ export class MessagingITC extends ITC {
|
|
|
76
77
|
|
|
77
78
|
try {
|
|
78
79
|
// Get the next worker for the application
|
|
79
|
-
const worker = this
|
|
80
|
+
const worker = this._getNextWorker(application)
|
|
80
81
|
|
|
81
82
|
if (!worker) {
|
|
82
83
|
throw new MessagingError(application, 'No workers available')
|
|
@@ -85,8 +86,9 @@ export class MessagingITC extends ITC {
|
|
|
85
86
|
if (!worker.channel) {
|
|
86
87
|
// Use twice the value here as a fallback measure. The target handler in the main thread is forwarding
|
|
87
88
|
// the request to the worker, using executeWithTimeout with the user set timeout value.
|
|
89
|
+
const itc = getITC()
|
|
88
90
|
const channel = await executeWithTimeout(
|
|
89
|
-
|
|
91
|
+
itc.send('getWorkerMessagingChannel', {
|
|
90
92
|
id: this.#id,
|
|
91
93
|
application: worker.application,
|
|
92
94
|
worker: worker.worker
|
|
@@ -100,10 +102,7 @@ export class MessagingITC extends ITC {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
worker.channel = channel
|
|
103
|
-
this
|
|
104
|
-
|
|
105
|
-
channel[kPendingResponses] = new Map()
|
|
106
|
-
channel.on('close', this.#handlePendingResponse.bind(this, channel))
|
|
105
|
+
this._setupChannel(channel)
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
const context = { ...options }
|
|
@@ -164,13 +163,11 @@ export class MessagingITC extends ITC {
|
|
|
164
163
|
|
|
165
164
|
async addSource (channel) {
|
|
166
165
|
this.#sources.add(channel)
|
|
167
|
-
this
|
|
166
|
+
this._setupChannel(channel)
|
|
167
|
+
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
channel.on('close', () => {
|
|
172
|
-
this.#sources.delete(channel)
|
|
173
|
-
})
|
|
169
|
+
_getNextWorker (application) {
|
|
170
|
+
return this.#workers.next(application)
|
|
174
171
|
}
|
|
175
172
|
|
|
176
173
|
_send (request, context) {
|
|
@@ -181,7 +178,7 @@ export class MessagingITC extends ITC {
|
|
|
181
178
|
channel[kPendingResponses].set(request.reqId, { application, request })
|
|
182
179
|
}
|
|
183
180
|
|
|
184
|
-
channel.postMessage(sanitize(request, transferList),
|
|
181
|
+
channel.postMessage(sanitize(request, transferList), transferList)
|
|
185
182
|
}
|
|
186
183
|
|
|
187
184
|
_createClosePromise () {
|
|
@@ -209,11 +206,22 @@ export class MessagingITC extends ITC {
|
|
|
209
206
|
this.#sources.clear()
|
|
210
207
|
}
|
|
211
208
|
|
|
212
|
-
|
|
209
|
+
_setupChannel (channel) {
|
|
210
|
+
if (channel[kPendingResponses]) {
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
channel[kPendingResponses] = new Map()
|
|
215
|
+
|
|
213
216
|
// Setup the message for processing
|
|
214
217
|
channel.on('message', event => {
|
|
215
218
|
this.#listener(event, { channel, message: event })
|
|
216
219
|
})
|
|
220
|
+
|
|
221
|
+
channel.on('close', () => {
|
|
222
|
+
this.#sources.delete(channel)
|
|
223
|
+
this.#handlePendingResponse(channel)
|
|
224
|
+
})
|
|
217
225
|
}
|
|
218
226
|
|
|
219
227
|
#updateWorkers (event) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getITC } from '@platformatic/globals'
|
|
2
2
|
|
|
3
3
|
export class SharedContext {
|
|
4
4
|
constructor () {
|
|
@@ -6,12 +6,14 @@ export class SharedContext {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
update (context, options = {}) {
|
|
9
|
-
|
|
9
|
+
const itc = getITC()
|
|
10
|
+
return itc.send('updateSharedContext', { ...options, context })
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
get () {
|
|
13
14
|
if (this.sharedContext === null) {
|
|
14
|
-
|
|
15
|
+
const itc = getITC()
|
|
16
|
+
this.sharedContext = itc.send('getSharedContext')
|
|
15
17
|
}
|
|
16
18
|
return this.sharedContext
|
|
17
19
|
}
|
package/lib/worker/symbols.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const kConfig = Symbol.for('plt.runtime.config')
|
|
2
|
-
export const kId = Symbol.for('plt.runtime.id')
|
|
2
|
+
export const kId = Symbol.for('plt.runtime.id')
|
|
3
3
|
export const kFullId = Symbol.for('plt.runtime.fullId')
|
|
4
4
|
export const kApplicationId = Symbol.for('plt.runtime.application.id')
|
|
5
5
|
export const kWorkerId = Symbol.for('plt.runtime.worker.id')
|
|
@@ -8,7 +8,6 @@ export const kHealthCheckTimer = Symbol.for('plt.runtime.worker.healthCheckTimer
|
|
|
8
8
|
export const kWorkerStatus = Symbol('plt.runtime.worker.status')
|
|
9
9
|
export const kWorkerHealthSignals = Symbol.for('plt.runtime.worker.healthSignals')
|
|
10
10
|
export const kWorkerStartTime = Symbol.for('plt.runtime.worker.startTime')
|
|
11
|
-
export const kInterceptors = Symbol.for('plt.runtime.worker.interceptors')
|
|
12
11
|
export const kLastHealthCheckELU = Symbol.for('plt.runtime.worker.lastHealthCheckELU')
|
|
13
12
|
export const kLastWorkerScalerELU = Symbol.for('plt.runtime.worker.lastWorkerScalerELU')
|
|
14
13
|
export const kInterceptorReadyPromise = Symbol.for('plt.runtime.worker.interceptorReadyPromise')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.57.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@fastify/formbody": "^8.0.0",
|
|
21
21
|
"atomic-sleep": "^1.0.0",
|
|
22
22
|
"autocannon": "^8.0.0",
|
|
23
|
-
"c8": "^
|
|
23
|
+
"c8": "^11.0.0",
|
|
24
24
|
"cleaner-spec-reporter": "^0.5.0",
|
|
25
25
|
"eslint": "9",
|
|
26
26
|
"execa": "^9.0.0",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"typescript": "^5.5.4",
|
|
37
37
|
"undici-oidc-interceptor": "^0.5.0",
|
|
38
38
|
"why-is-node-running": "^2.2.2",
|
|
39
|
-
"@platformatic/db": "3.
|
|
40
|
-
"@platformatic/
|
|
41
|
-
"@platformatic/
|
|
42
|
-
"@platformatic/
|
|
43
|
-
"@platformatic/
|
|
44
|
-
"@platformatic/
|
|
45
|
-
"@platformatic/
|
|
46
|
-
"@platformatic/
|
|
39
|
+
"@platformatic/db": "3.57.0",
|
|
40
|
+
"@platformatic/node": "3.57.0",
|
|
41
|
+
"@platformatic/composer": "3.57.0",
|
|
42
|
+
"@platformatic/gateway": "3.57.0",
|
|
43
|
+
"@platformatic/service": "3.57.0",
|
|
44
|
+
"@platformatic/sql-graphql": "3.57.0",
|
|
45
|
+
"@platformatic/wattpm-pprof-capture": "3.57.0",
|
|
46
|
+
"@platformatic/sql-mapper": "3.57.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@fastify/accepts": "^5.0.0",
|
|
@@ -70,15 +70,16 @@
|
|
|
70
70
|
"semgrator": "^0.3.0",
|
|
71
71
|
"sonic-boom": "^4.2.0",
|
|
72
72
|
"systeminformation": "^5.27.11",
|
|
73
|
-
"undici": "^7.
|
|
73
|
+
"undici": "^7.27.2",
|
|
74
74
|
"undici-thread-interceptor": "^1.3.1",
|
|
75
75
|
"ws": "^8.16.0",
|
|
76
|
-
"@platformatic/
|
|
77
|
-
"@platformatic/
|
|
78
|
-
"@platformatic/
|
|
79
|
-
"@platformatic/
|
|
80
|
-
"@platformatic/
|
|
81
|
-
"@platformatic/
|
|
76
|
+
"@platformatic/basic": "3.57.0",
|
|
77
|
+
"@platformatic/globals": "3.57.0",
|
|
78
|
+
"@platformatic/generators": "3.57.0",
|
|
79
|
+
"@platformatic/foundation": "3.57.0",
|
|
80
|
+
"@platformatic/itc": "3.57.0",
|
|
81
|
+
"@platformatic/metrics": "3.57.0",
|
|
82
|
+
"@platformatic/telemetry": "3.57.0"
|
|
82
83
|
},
|
|
83
84
|
"engines": {
|
|
84
85
|
"node": ">=22.19.0"
|