@lenne.tech/nest-server 11.46.10 → 11.46.11
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/FRAMEWORK-API.md +1 -1
- package/dist/core/modules/health-check/core-health-check.service.d.ts +12 -0
- package/dist/core/modules/health-check/core-health-check.service.js +40 -2
- package/dist/core/modules/health-check/core-health-check.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/migration-guides/11.46.10-to-11.46.11.md +57 -0
- package/package.json +1 -1
- package/src/core/modules/health-check/core-health-check.service.ts +74 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Migration Guide: 11.46.10 → 11.46.11
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None. Changed defaults: the MongoDB health check pings instead of reading `readyState`, and waits up to 2000 ms (§1) |
|
|
8
|
+
| **New Features** | None |
|
|
9
|
+
| **Bugfixes** | The health check reported a reachable MongoDB replica set as down whenever the driver briefly saw no primary (§1) |
|
|
10
|
+
| **Migration Effort** | None |
|
|
11
|
+
|
|
12
|
+
## Quick Migration
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @lenne.tech/nest-server@11.46.11
|
|
16
|
+
pnpm run build
|
|
17
|
+
pnpm test
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Vendor mode**: run `/lt-dev:backend:update-nest-server-core` with `--target 11.46.11` as usual.
|
|
21
|
+
|
|
22
|
+
## 1. Health check: the MongoDB check pings, and waits up to 2000 ms
|
|
23
|
+
|
|
24
|
+
Terminus 11's `MongooseHealthIndicator` does not ping the database: it reports up when the Mongoose connection's
|
|
25
|
+
`readyState` is 1 and down otherwise. Mongoose sets `disconnected` as soon as the driver's topology briefly sees no
|
|
26
|
+
primary: a replica set without `ReplicaSetWithPrimary`, a single server turning `Unknown`. One lost heartbeat is
|
|
27
|
+
enough, while the database answers in milliseconds and the application's own queries simply wait for the driver's
|
|
28
|
+
server selection. On a cluster with managed MongoDB replica sets this caused far more than 95 % of all "database
|
|
29
|
+
down" alarms, and three in a row took the pod out of the readiness rotation.
|
|
30
|
+
|
|
31
|
+
The core now sends a real `ping` (`CoreHealthCheckService.mongoPingCheck()` / `pingMongoDb()`). It waits for the
|
|
32
|
+
driver's server selection like any query, so the check reports down only when the database does not answer within
|
|
33
|
+
the timeout (message `timeout of <n>ms exceeded`), when the ping fails (the driver's message), or when the initial
|
|
34
|
+
connect has not finished yet (`Not connected to database`).
|
|
35
|
+
|
|
36
|
+
The timeout is now **2000 ms** (`DEFAULT_DATABASE_PING_TIMEOUT_MS`), unless
|
|
37
|
+
`healthCheck.configs.database.options.timeout` sets another value. Before, it was 300 ms without configured options
|
|
38
|
+
and 1000 ms with options but no `timeout`.
|
|
39
|
+
|
|
40
|
+
**Check:** nothing to change. Keep your probe timeout above 2 s. A subclass of `CoreHealthCheckService` keeps the new
|
|
41
|
+
check; one that builds its own MongoDB indicator with `this.db.pingCheck()` keeps Terminus' `readyState` check. To keep
|
|
42
|
+
the old timeout, set `healthCheck.configs.database.options.timeout: 300`.
|
|
43
|
+
|
|
44
|
+
## 2. Audit: minimatch 11.0.10, glob residual
|
|
45
|
+
|
|
46
|
+
Two advisories reached GitHub's global database on 2026-12-04, so `pnpm audit` fails without action:
|
|
47
|
+
|
|
48
|
+
- GHSA-3924-r96c-gp9w (low, minimatch 11.0.6 to 11.0.9): nest-server overrides it to 11.0.10. The override does not
|
|
49
|
+
reach your project; where `pnpm audit` reports it, add `'minimatch@>=11.0.0 <11.0.10': '11.0.10'` to `overrides` in
|
|
50
|
+
your `pnpm-workspace.yaml`.
|
|
51
|
+
- GHSA-c6wh-w8c3-cv3g (moderate, glob up to 14.0.5): fixed only in glob 14.0.6, while `@nestjs/cli` 11.0.24 (the newest
|
|
52
|
+
11.x) pins glob 13.0.6 exactly. Dev tooling only (the CLI's glob matches your own build patterns). nest-server
|
|
53
|
+
declares it like GHSA-qxr8-q827-836c: `ignoreGhsas` plus `unusableFixConsumers: { GHSA-c6wh-w8c3-cv3g: '@nestjs/cli@11.0.24 cannot use 14.0.6' }`. Do the same in your project if `pnpm audit` reports it.
|
|
54
|
+
|
|
55
|
+
## Module Documentation
|
|
56
|
+
|
|
57
|
+
- `src/core/modules/health-check/core-health-check.service.ts`: `mongoPingCheck()`, `pingMongoDb()`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "11.46.
|
|
3
|
+
"version": "11.46.11",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
1
|
+
import { Injectable, Optional } from '@nestjs/common';
|
|
2
|
+
import { InjectConnection } from '@nestjs/mongoose';
|
|
2
3
|
import {
|
|
3
4
|
DiskHealthIndicator,
|
|
4
5
|
HealthCheckResult,
|
|
5
6
|
HealthCheckService,
|
|
7
|
+
HealthIndicatorService,
|
|
6
8
|
MemoryHealthIndicator,
|
|
7
9
|
MongooseHealthIndicator,
|
|
8
10
|
} from '@nestjs/terminus';
|
|
@@ -12,6 +14,20 @@ import type { DiskHealthIndicatorOptions } from '@nestjs/terminus/dist/health-in
|
|
|
12
14
|
import { getBuildInfo } from '../../common/helpers/meta.helper';
|
|
13
15
|
import { ConfigService } from '../../common/services/config.service';
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* How long the MongoDB ping may take before the health check reports the database as down, unless
|
|
19
|
+
* `healthCheck.configs.database.options.timeout` sets another value (11.46.11; before: 300 ms without options, 1000 ms
|
|
20
|
+
* with options but no `timeout`). The ping waits for the driver's server selection (see
|
|
21
|
+
* {@link CoreHealthCheckService.pingMongoDb}), which rides out a replica set that briefly sees no primary; 2 s still
|
|
22
|
+
* fails a database that does not answer and stays below the readiness probe timeout of the lt charts (3 s).
|
|
23
|
+
*/
|
|
24
|
+
export const DEFAULT_DATABASE_PING_TIMEOUT_MS = 2000;
|
|
25
|
+
|
|
26
|
+
/** The part of a Mongoose connection the health check's MongoDB ping uses */
|
|
27
|
+
export interface IHealthCheckMongoConnection {
|
|
28
|
+
db?: { command(command: Record<string, unknown>): Promise<unknown> } | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
15
31
|
/**
|
|
16
32
|
* Core health check service
|
|
17
33
|
* Inspired by https://mobileappcircular.com/marketplace-backend-creating-a-health-check-endpoint-in-nestjs-app-using-terminus-25727e96c7d2
|
|
@@ -26,13 +42,21 @@ export class CoreHealthCheckService {
|
|
|
26
42
|
protected memory: MemoryHealthIndicator,
|
|
27
43
|
) {}
|
|
28
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The application's Mongoose connection for the MongoDB ping (11.46.11). Injected as a property, so a project
|
|
47
|
+
* subclass with its own constructor receives it too.
|
|
48
|
+
*/
|
|
49
|
+
@Optional()
|
|
50
|
+
@InjectConnection()
|
|
51
|
+
protected mongoConnection?: IHealthCheckMongoConnection | null;
|
|
52
|
+
|
|
29
53
|
healthCheck(): Promise<HealthCheckResult> {
|
|
30
54
|
const healthIndicatorFunctions = [];
|
|
31
55
|
if (this.config.get<boolean>('healthCheck.configs.database.enabled')) {
|
|
32
56
|
healthIndicatorFunctions.push(() =>
|
|
33
|
-
this.
|
|
57
|
+
this.mongoPingCheck(
|
|
34
58
|
this.config.get<string>('healthCheck.configs.database.key') ?? 'database',
|
|
35
|
-
this.config.get<MongoosePingCheckSettings>('healthCheck.configs.database.options') ?? {
|
|
59
|
+
this.config.get<MongoosePingCheckSettings>('healthCheck.configs.database.options') ?? {},
|
|
36
60
|
),
|
|
37
61
|
);
|
|
38
62
|
}
|
|
@@ -79,4 +103,51 @@ export class CoreHealthCheckService {
|
|
|
79
103
|
|
|
80
104
|
return this.health.check(healthIndicatorFunctions);
|
|
81
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The MongoDB indicator (11.46.11): up when the database answers a real `ping` within the timeout.
|
|
109
|
+
*
|
|
110
|
+
* Replaces Terminus' `MongooseHealthIndicator.pingCheck()`, which in Terminus 11 does not ping at all: it reports
|
|
111
|
+
* up when the connection's `readyState` is 1 and down otherwise. Mongoose sets `disconnected` as soon as the
|
|
112
|
+
* driver's topology briefly sees no primary (a replica set without `ReplicaSetWithPrimary`, a single server turning
|
|
113
|
+
* `Unknown`): one lost heartbeat is enough, while the database answers in milliseconds and the application's own
|
|
114
|
+
* queries just wait for the driver's server selection. On a cluster with managed MongoDB replica sets that produced
|
|
115
|
+
* far more than 95 % of all "database down" alarms. Falls back to Terminus' check when no connection is available.
|
|
116
|
+
*/
|
|
117
|
+
protected async mongoPingCheck(key: string, options: MongoosePingCheckSettings) {
|
|
118
|
+
const connection: IHealthCheckMongoConnection | null | undefined = options.connection ?? this.mongoConnection;
|
|
119
|
+
if (!connection) {
|
|
120
|
+
return this.db.pingCheck(key, { timeout: DEFAULT_DATABASE_PING_TIMEOUT_MS, ...options });
|
|
121
|
+
}
|
|
122
|
+
const timeout = options.timeout || DEFAULT_DATABASE_PING_TIMEOUT_MS;
|
|
123
|
+
const check = new HealthIndicatorService().check(key);
|
|
124
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
125
|
+
try {
|
|
126
|
+
await Promise.race([
|
|
127
|
+
this.pingMongoDb(connection),
|
|
128
|
+
new Promise<never>((_, reject) => {
|
|
129
|
+
timer = setTimeout(() => reject(new Error(`timeout of ${timeout}ms exceeded`)), timeout);
|
|
130
|
+
}),
|
|
131
|
+
]);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return check.down({ message: (error as Error)?.message ?? String(error) });
|
|
134
|
+
} finally {
|
|
135
|
+
clearTimeout(timer);
|
|
136
|
+
}
|
|
137
|
+
return check.up();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Pings the MongoDB the application uses: a real `ping` command that waits for the driver's server selection like
|
|
142
|
+
* any query — deliberately without a `readyState` check (see {@link mongoPingCheck}).
|
|
143
|
+
*
|
|
144
|
+
* @param connection The Mongoose connection (`healthCheck.configs.database.options.connection` or the injected one)
|
|
145
|
+
*/
|
|
146
|
+
protected async pingMongoDb(connection: IHealthCheckMongoConnection): Promise<void> {
|
|
147
|
+
if (!connection.db) {
|
|
148
|
+
// Not connected yet (the initial connect is still running) or never connected
|
|
149
|
+
throw new Error('Not connected to database');
|
|
150
|
+
}
|
|
151
|
+
await connection.db.command({ ping: 1 });
|
|
152
|
+
}
|
|
82
153
|
}
|