Skip to content

fix(core): close all named connections on shutdown; consolidate open PRs, 100% coverage and security updates - #311

Merged
juandav merged 4 commits into
mainfrom
chore/consolidate-open-prs
Oct 4, 2026
Merged

juandav merged 4 commits into
mainfrom
chore/consolidate-open-prs

Conversation

@juandav

@juandav juandav commented Oct 4, 2026

Copy link
Copy Markdown
Member

Consolidates every open PR into a single change, enforces 100% unit test coverage and clears the open security advisories.

Supersedes #307, #306, #305, #304, #303 and #300.

1. Fix: named connections were never closed on shutdown (from #307)

RedisCoreModule keeps the connection tokens in a static Set, but Nest creates one module instance per forRoot/forRootAsync and calls onApplicationShutdown on each one. The first instance cleared the set after its loop, so the others found it empty and never called quit() on their clients. The result was open handles (Jest did not exit…), exactly as #307 describes.

moduleRef.get is strict by default, so each instance already resolves (and quits) only its own connection. The fix just drops the clear().

#307 proposed delete(token) after each successful quit instead. That still breaks when two apps register the same connection name (the first app to close deletes the token, so the second one skips its connection). The new regression test should close connections of an app shut down after another one fails with both the current code and the #307 approach, and passes with this one.

Verified end to end with the packed package (3 connections: default, main, sub):

connections closed
published 2.2.2 default
this branch default, main, sub

2. 100% coverage, enforced

  • jest.config.js collects coverage from every source file (before, files no test imported didn't count) and sets coverageThreshold to 100 for statements, branches, functions and lines.
  • pnpm test runs with --coverage, so CI fails if coverage drops.
  • New tests: health module/provider wiring, the public API (index.ts), connections created without options, connections without quit(), and the shutdown regressions above.
All files | 100 | 100 | 100 | 100
Tests: 94 passed, 94 total

3. Dependencies (Dependabot PRs)

Package Before After PR
typescript 5.9.3 6.0.3 #300
@biomejs/biome 2.4.8 2.5.15 #303
@nestjs/cli 11.0.16 11.0.24 #304
@nestjs/schematics 11.0.9 11.1.0 #305
turbo 2.8.20 2.11.7 #306
ts-jest 29.4.6 29.4.14 required for TS 6

The Dependabot versions were superseded by newer patches in the same lines, so this PR uses the latest in each.

TypeScript 6 changes defaults (strict, esModuleInterop, types: []):

  • Library: types: ["jest"] and two non-null assertions in redis-options.provider.ts. The emitted .d.ts files are identical to TS 5.9's. The only JS change is __importDefault(require("ioredis")), which is equivalent because ioredis exports itself as default.
  • Samples: rootDir, types, strictPropertyInitialization: false, drop the deprecated baseUrl, import request from 'supertest', and a parameter type in roles.guard.ts.

4. Security

pnpm audit
main 117 (3 critical, 61 high, 43 moderate, 10 low)
this branch 2 high, no upstream patch
  • Lockfile regenerated from scratch, plus updated dev dependencies: @nestjs/* 11.2.7, Docusaurus 3.10.2, jest 30.5.2, supertest 7.3.1, ts-loader 9.6.2, @changesets/cli ^2.31.1.
  • New override uuid@<11.1.1 → ^11.1.1 (pulled in by sockjs via webpack-dev-server; it only uses v4, which uuid 11 still exports in CJS).
  • No version in the new lockfile falls inside the vulnerable range of any open Dependabot alert on the repo (checked against the API).
  • Remaining, with no patched version upstream, dev tooling only: http-cache-semantics (Docusaurus → update-notifier) and braces (@changesets/cli 2 → micromatch; it goes away with changesets 3, a major left for a separate PR).
  • None of the advisories affected the published package: at runtime it only depends on peers plus the optional @nestjs/terminus.
  • Packaging: the package relied on .npmignore, so with tests now writing coverage/ the release job would have published it to npm (with runner paths). It now uses "files": ["dist", "CHANGELOG.md"]. The tarball has the same file list as 2.2.2.

5. Other

  • The single sample didn't build on main because it imported ioredis without depending on it. Fixed in both samples.
  • .gitignore: coverage at any level and *.tsbuildinfo.
  • CLAUDE.md updated (shutdown behaviour, coverage, TS 6, overrides).

Verification

  • pnpm check, tsc --noEmit, pnpm build, pnpm test (library + samples) and the sample e2e tests: OK
  • pnpm install --frozen-lockfile: OK
  • docusaurus build: OK

RedisCoreModule cleared the shared static token set at the end of the
first instance's onApplicationShutdown. With two or more named
connections, the remaining instances found an empty set and never quit
their clients, leaving open handles (e.g. Jest not exiting).

moduleRef.get is strict, so each instance already resolves only its own
connection; the set no longer needs to be cleared or pruned. Pruning
(as proposed in #307) would still break a second app registering the
same connection name, which the new regression test covers.

Supersedes #307.
Collect coverage from every source file (not only the ones loaded by a
test) and fail below 100% statements, branches, functions and lines.
The package test script now runs with --coverage so CI applies the gate.

Adds the tests that were missing to reach it: health module/provider
wiring, the public API barrel, connections created without options, and
connections that do not expose quit().
Consolidates the open Dependabot PRs (#300, #303, #304, #305, #306):
- typescript 5.9.3 -> 6.0.3, ts-jest 29.4.6 -> 29.4.14
- @biomejs/biome 2.4.8 -> 2.5.15, turbo 2.8.20 -> 2.11.7
- @nestjs/cli 11.0.16 -> 11.0.24, @nestjs/schematics 11.0.9 -> 11.1.0

Adapts to the TypeScript 6 defaults (strict, esModuleInterop, empty
types): the library's emitted declarations are unchanged.

Security: refreshes the lockfile and dev dependencies (@nestjs/* 11.2.7,
Docusaurus 3.10.2, jest 30.5.2, supertest 7.3.1) and overrides uuid for
sockjs. pnpm audit goes from 117 to 2 findings, both without an upstream
patch and limited to dev tooling. None affected the published package.

Also fixes the single sample, which did not build because it imported
ioredis without depending on it.
The package relied on .npmignore, so anything new in the package folder
was published. With tests now writing a coverage report, the release
job would have shipped coverage/ (including CI runner paths) to npm.
Use a files allowlist instead; the tarball keeps the same file list as
2.2.2.
@juandav

juandav commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

Remaining pnpm audit findings (no upstream patch)

Advisory Package Reached through Exploitable here?
GHSA-vfj7-8cjw-p6xm (high, DoS) braces ≤ 3.0.3 (latest release) jest, chokidar, Docusaurus, @changesets/cli No: it needs an attacker-controlled glob pattern; here patterns only come from repo config, and only in dev tooling.
GHSA-ch52-4w7c-c8xp (high) http-cache-semantics ≤ 4.2.0 Docusaurus → update-notifier No: the issue is leaking cached responses between users of a shared HTTP cache; update-notifier is a single-user CLI version check.

I also tried @changesets/cli 3 (it drops micromatch): changeset version produces the same package.json, but braces stays through jest/Docusaurus and the CHANGELOG indentation changes. Since it doesn't fix the advisory, I left it out of this PR.

Neither package ends up in the published @nestjs-modules/ioredis tarball.

@juandav
juandav merged commit 45a0193 into main Oct 4, 2026
5 checks passed
@juandav
juandav deleted the chore/consolidate-open-prs branch October 4, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant