@nxtedition/lib 28.0.25 → 28.0.26

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 (3) hide show
  1. package/app.js +49 -3
  2. package/http.js +4 -4
  3. package/package.json +3 -3
package/app.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readFileSync } from 'node:fs'
2
2
  import * as inspector from 'node:inspector'
3
3
  import fs from 'node:fs'
4
+ import util from 'node:util'
4
5
  import os from 'node:os'
5
6
  import http from 'node:http'
6
7
  import net from 'node:net'
@@ -40,6 +41,7 @@ import makeUnderPressure from './under-pressure.js'
40
41
  import { nice } from '@nxtedition/sched'
41
42
  import { setAffinity } from './numa.js'
42
43
  import { getContainerMemoryLimit, getContainerMemoryUsage } from './memory.js'
44
+ import { serializeError } from './errors.js'
43
45
 
44
46
  /**
45
47
  * @param {object} appConfig
@@ -688,6 +690,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
688
690
  sockets: globalThis.__undici_sockets?.size ?? 0,
689
691
  }
690
692
 
693
+ const errors = []
694
+
691
695
  if (statsMap) {
692
696
  memory.totalHeapTotal = 0
693
697
  memory.totalHeapUsed = 0
@@ -707,6 +711,10 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
707
711
  http.totalPending += stats.http?.pending ?? 0
708
712
 
709
713
  undici.totalSockets += stats.undici?.sockets ?? 0
714
+
715
+ if (stats.error) {
716
+ errors.push(stats.error)
717
+ }
710
718
  }
711
719
  }
712
720
 
@@ -718,6 +726,9 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
718
726
  couch: couch?.stats,
719
727
  lag: toobusy?.lag(),
720
728
  version: process.version,
729
+ error: errors.length
730
+ ? serializeError(errors.length > 1 ? new AggregateError(errors) : errors[0])
731
+ : null,
721
732
  underPressure: underPressure?.isUnderPressure() ? underPressure.getPressure() : null,
722
733
  cpu,
723
734
  memory,
@@ -757,7 +768,15 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
757
768
  appDestroyers.unshift(
758
769
  monitorProviders.stats$
759
770
  .subscribe((stats) => {
760
- statsBC.postMessage({ id: threadId, data: stats })
771
+ try {
772
+ statsBC.postMessage({ id: threadId, data: stats })
773
+ } catch (err) {
774
+ statsBC.postMessage({ id: threadId, data: { error: serializeError(err) } })
775
+ logger.error(
776
+ { err, data: util.inspect(stats, { depth: 16 }) },
777
+ 'stats broadcast failed',
778
+ )
779
+ }
761
780
  })
762
781
  .add(() => {
763
782
  statsBC.postMessage({ id: threadId, data: undefined })
@@ -831,9 +850,17 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
831
850
  makeStatusPipe('status'),
832
851
  ),
833
852
  monitorProviders.stats$?.pipe(
834
- rxjs.map(({ memory, heap, utilization, undici, http }) => {
853
+ rxjs.map(({ memory, heap, utilization, undici, http, error }) => {
835
854
  const messages = []
836
855
 
856
+ if (error) {
857
+ messages.push({
858
+ id: 'app:monitor_stats_error',
859
+ level: 50,
860
+ msg: `Monitor Stats Error: ${error.message}`,
861
+ })
862
+ }
863
+
837
864
  if (memory?.containerLimit) {
838
865
  const usagePercent = (memory.containerUsage / memory.containerLimit) * 100
839
866
  messages.push({
@@ -1067,7 +1094,26 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
1067
1094
  appDestroyers.unshift(
1068
1095
  monitorProviders.status$
1069
1096
  .subscribe((stats) => {
1070
- statusBC.postMessage({ id: threadId, data: stats })
1097
+ try {
1098
+ statusBC.postMessage({ id: threadId, data: stats })
1099
+ } catch (err) {
1100
+ statusBC.postMessage({
1101
+ id: threadId,
1102
+ data: {
1103
+ messages: [
1104
+ {
1105
+ id: 'app:monitor_status_broadcast_error_' + threadId,
1106
+ level: 50,
1107
+ msg: `Monitor Status Error: ${err.message}`,
1108
+ },
1109
+ ],
1110
+ },
1111
+ })
1112
+ logger.error(
1113
+ { err, data: util.inspect(stats, { depth: 16 }) },
1114
+ 'status broadcast failed',
1115
+ )
1116
+ }
1071
1117
  })
1072
1118
  .add(() => {
1073
1119
  statusBC.postMessage({ id: threadId, data: undefined })
package/http.js CHANGED
@@ -572,7 +572,7 @@ export class ServerResponse extends http.ServerResponse {
572
572
 
573
573
  /**
574
574
  * @param {Buffer|string} chunk
575
- * @param {string} [encoding]
575
+ * @param {NodeJS.BufferEncoding} [encoding]
576
576
  * @param {(err: Error) => void} [callback]
577
577
  */
578
578
  write(chunk, encoding, callback) {
@@ -599,7 +599,7 @@ export class ServerResponse extends http.ServerResponse {
599
599
 
600
600
  /**
601
601
  * @param {Buffer|string} chunk
602
- * @param {string} [encoding]
602
+ * @param {NodeJS.BufferEncoding} [encoding]
603
603
  * @param {(err: Error) => void} [callback]
604
604
  */
605
605
  end(chunk, encoding, callback) {
@@ -811,7 +811,7 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
811
811
 
812
812
  /**
813
813
  * @param {Buffer|string} chunk
814
- * @param {string} [encoding]
814
+ * @param {NodeJS.BufferEncoding} [encoding]
815
815
  * @param {(err: Error) => void} [callback]
816
816
  */
817
817
  write(chunk, encoding, callback) {
@@ -838,7 +838,7 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
838
838
 
839
839
  /**
840
840
  * @param {Buffer|string} chunk
841
- * @param {string} [encoding]
841
+ * @param {NodeJS.BufferEncoding} [encoding]
842
842
  * @param {(err: Error) => void} [callback]
843
843
  */
844
844
  end(chunk, encoding, callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "28.0.25",
3
+ "version": "28.0.26",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -52,7 +52,7 @@
52
52
  "@elastic/transport": "^8.9.3",
53
53
  "@nxtedition/nxt-undici": "^7.1.9",
54
54
  "@nxtedition/sched": "^1.0.2",
55
- "@nxtedition/template": "^1.0.10",
55
+ "@nxtedition/template": "^1.0.11",
56
56
  "@nxtedition/weak-cache": "^1.0.2",
57
57
  "@nxtedition/yield": "^1.0.2",
58
58
  "diff": "5.2.0",
@@ -92,5 +92,5 @@
92
92
  "canvas": "^3.1.0",
93
93
  "rxjs": "^7.0.0"
94
94
  },
95
- "gitHead": "48c8835b26082e9c7f427a1dca71c4f9fa3e2091"
95
+ "gitHead": "007b8e2002dfc572af40f794575ded6ad79620e7"
96
96
  }