@nxtedition/lib 17.2.19 → 17.2.20

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.
Files changed (2) hide show
  1. package/app.js +20 -9
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -33,6 +33,8 @@ export function makeApp(appConfig, onTerminate) {
33
33
  let logger
34
34
  let trace
35
35
 
36
+ const destroyers = []
37
+
36
38
  if (net.setDefaultAutoSelectFamily) {
37
39
  net.setDefaultAutoSelectFamily(false)
38
40
  }
@@ -111,7 +113,7 @@ export function makeApp(appConfig, onTerminate) {
111
113
  }
112
114
  }
113
115
 
114
- const destroyers = []
116
+ const appDestroyers = []
115
117
 
116
118
  const serviceName = appConfig.name
117
119
  const serviceModule = appConfig.module ?? 'main'
@@ -142,7 +144,7 @@ export function makeApp(appConfig, onTerminate) {
142
144
  base: loggerConfig?.base ? { ...loggerConfig.base } : {},
143
145
  })
144
146
 
145
- destroyers.push(
147
+ appDestroyers.push(
146
148
  () =>
147
149
  new Promise((resolve, reject) => {
148
150
  try {
@@ -182,6 +184,14 @@ export function makeApp(appConfig, onTerminate) {
182
184
  }
183
185
  }
184
186
 
187
+ for (const { reason: err } of await Promise.allSettled(
188
+ appDestroyers.filter(Boolean).map((fn) => fn(logger)),
189
+ )) {
190
+ if (err) {
191
+ logger.error({ err }, 'shutdown error')
192
+ }
193
+ }
194
+
185
195
  setTimeout(() => {
186
196
  logger.error('aborting')
187
197
  if (isMainThread) {
@@ -239,7 +249,7 @@ export function makeApp(appConfig, onTerminate) {
239
249
 
240
250
  if (couchConfig.url) {
241
251
  couch = makeCouch(couchConfig)
242
- destroyers.push(() => couch.close())
252
+ appDestroyers.push(() => couch.close())
243
253
  } else {
244
254
  throw new Error('invalid couch config')
245
255
  }
@@ -330,7 +340,7 @@ export function makeApp(appConfig, onTerminate) {
330
340
 
331
341
  globalThis.ds = ds
332
342
 
333
- destroyers.push(() => ds.close())
343
+ appDestroyers.push(() => ds.close())
334
344
  }
335
345
 
336
346
  if (appConfig.compiler) {
@@ -396,7 +406,7 @@ export function makeApp(appConfig, onTerminate) {
396
406
  }
397
407
  })
398
408
 
399
- destroyers.push(() => {
409
+ appDestroyers.push(() => {
400
410
  subscription.unsubscribe()
401
411
  })
402
412
  }
@@ -633,7 +643,7 @@ export function makeApp(appConfig, onTerminate) {
633
643
 
634
644
  monitorProviders.status$ = status$
635
645
 
636
- destroyers.push(() => {
646
+ appDestroyers.push(() => {
637
647
  loggerSubscription.unsubscribe()
638
648
  })
639
649
  }
@@ -653,7 +663,7 @@ export function makeApp(appConfig, onTerminate) {
653
663
  }
654
664
  })
655
665
 
656
- destroyers.push(() => {
666
+ appDestroyers.push(() => {
657
667
  if (unprovide) {
658
668
  unprovide()
659
669
  }
@@ -664,7 +674,7 @@ export function makeApp(appConfig, onTerminate) {
664
674
  if (appConfig.trace) {
665
675
  const traceConfig = { ...appConfig.trace, ...config.trace }
666
676
  if (traceConfig.url) {
667
- trace = makeTrace({ ...traceConfig, destroyers, logger, serviceName })
677
+ trace = makeTrace({ ...traceConfig, appDestroyers, logger, serviceName })
668
678
  }
669
679
  }
670
680
 
@@ -712,7 +722,7 @@ export function makeApp(appConfig, onTerminate) {
712
722
 
713
723
  server.listen(port)
714
724
 
715
- destroyers.push(() => new Promise((resolve) => server.close(resolve)))
725
+ appDestroyers.push(() => new Promise((resolve) => server.close(resolve)))
716
726
  }
717
727
  }
718
728
 
@@ -721,6 +731,7 @@ export function makeApp(appConfig, onTerminate) {
721
731
  nxt,
722
732
  logger,
723
733
  toobusy,
734
+ destroyers,
724
735
  couch,
725
736
  server,
726
737
  config,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "17.2.19",
3
+ "version": "17.2.20",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",