Skip to content

Commit 1aa33c3

Browse files
committed
fix: harden native addon lifecycle, shutdown semantics, and error propagation
- Eliminate Producer double-free by switching from AutoDeleteSendCallback to SendCallback - Replace ineffective set_shutdown_on_destroy with explicit shutdown in PushConsumer - Add shutdown_worker_active_ reentrancy guard to PushConsumer shutdown - Propagate consumer native errors to JS instead of silent RECONSUME_LATER nacks - Harden TSFN reference counting and lifecycle management - Fix race conditions between send/shutdown/finalize paths
1 parent a2d1a6a commit 1aa33c3

50 files changed

Lines changed: 7825 additions & 5710 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 95 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,40 @@ on:
1616
default: false
1717

1818
jobs:
19+
validate:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 22
29+
30+
- name: Setup pnpm
31+
uses: pnpm/action-setup@v4
32+
with:
33+
version: 11
34+
run_install: false
35+
36+
- name: Install dependencies
37+
run: pnpm install --frozen-lockfile --ignore-scripts
38+
39+
- name: Typecheck
40+
run: pnpm run typecheck
41+
42+
- name: Lint
43+
run: pnpm run lint:check
44+
45+
- name: Build test binary
46+
run: pnpm run build:test
47+
48+
- name: Test
49+
run: npx vitest run --reporter=verbose
50+
1951
linux-gnu-x64:
52+
needs: validate
2053
runs-on: ubuntu-24.04
2154
container:
2255
image: alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest
@@ -31,8 +64,9 @@ jobs:
3164

3265
- name: Install Node.js
3366
run: |
34-
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
67+
curl -fsSL https://rpm.nodesource.com/setup_22.x | bash -
3568
yum install -y nodejs
69+
npm install -g pnpm@11
3670
3771
- name: Setup Zig
3872
uses: mlugg/setup-zig@v2
@@ -53,14 +87,14 @@ jobs:
5387
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
5488
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
5589
56-
- name: Cache npm dependencies
90+
- name: Cache pnpm dependencies
5791
id: cache-npm
5892
uses: actions/cache@v4
5993
with:
6094
path: node_modules
61-
key: npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
95+
key: pnpm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('pnpm-lock.yaml') }}
6296
restore-keys: |
63-
npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-
97+
pnpm-${{ runner.os }}-${{ env.ZIG_TARGET }}-
6498
6599
- name: Cache RocketMQ native deps
66100
uses: actions/cache@v4
@@ -82,9 +116,9 @@ jobs:
82116
restore-keys: |
83117
addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-
84118
85-
- name: Install npm dependencies
119+
- name: Install dependencies
86120
if: steps.cache-npm.outputs.cache-hit != 'true'
87-
run: npm install --no-audit --prefer-offline
121+
run: pnpm install --no-frozen-lockfile --ignore-scripts
88122

89123
- name: Build RocketMQ native deps
90124
if: steps.cache-addon.outputs.cache-hit != 'true'
@@ -107,6 +141,7 @@ jobs:
107141
path: Release/linux-x86_64-gnu-rocketmq.node
108142

109143
linux-gnu-arm64:
144+
needs: validate
110145
runs-on: ubuntu-24.04-arm
111146
container:
112147
image: alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest
@@ -121,8 +156,9 @@ jobs:
121156

122157
- name: Install Node.js
123158
run: |
124-
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
159+
curl -fsSL https://rpm.nodesource.com/setup_22.x | bash -
125160
yum install -y nodejs
161+
npm install -g pnpm@11
126162
127163
- name: Setup Zig
128164
uses: mlugg/setup-zig@v2
@@ -143,14 +179,14 @@ jobs:
143179
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
144180
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
145181
146-
- name: Cache npm dependencies
182+
- name: Cache pnpm dependencies
147183
id: cache-npm
148184
uses: actions/cache@v4
149185
with:
150186
path: node_modules
151-
key: npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
187+
key: pnpm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('pnpm-lock.yaml') }}
152188
restore-keys: |
153-
npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-
189+
pnpm-${{ runner.os }}-${{ env.ZIG_TARGET }}-
154190
155191
- name: Cache RocketMQ native deps
156192
uses: actions/cache@v4
@@ -172,9 +208,9 @@ jobs:
172208
restore-keys: |
173209
addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-
174210
175-
- name: Install npm dependencies
211+
- name: Install dependencies
176212
if: steps.cache-npm.outputs.cache-hit != 'true'
177-
run: npm install --no-audit --prefer-offline
213+
run: pnpm install --no-frozen-lockfile --ignore-scripts
178214

179215
- name: Build RocketMQ native deps
180216
if: steps.cache-addon.outputs.cache-hit != 'true'
@@ -197,9 +233,10 @@ jobs:
197233
path: Release/linux-aarch64-gnu-rocketmq.node
198234

199235
linux-musl-x64:
236+
needs: validate
200237
runs-on: ubuntu-24.04
201238
container:
202-
image: node:20-alpine
239+
image: node:22-alpine
203240
env:
204241
ZIG_TARGET: x86_64-linux-musl
205242
steps:
@@ -209,6 +246,9 @@ jobs:
209246
- name: Install system dependencies
210247
run: apk add --no-cache bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig
211248

249+
- name: Install pnpm
250+
run: npm install -g pnpm@11
251+
212252
- name: Setup Zig
213253
uses: mlugg/setup-zig@v2
214254
with:
@@ -228,14 +268,14 @@ jobs:
228268
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
229269
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
230270
231-
- name: Cache npm dependencies
271+
- name: Cache pnpm dependencies
232272
id: cache-npm
233273
uses: actions/cache@v4
234274
with:
235275
path: node_modules
236-
key: npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
276+
key: pnpm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('pnpm-lock.yaml') }}
237277
restore-keys: |
238-
npm-${{ runner.os }}-
278+
pnpm-${{ runner.os }}-
239279
240280
- name: Cache RocketMQ native deps
241281
uses: actions/cache@v4
@@ -257,9 +297,9 @@ jobs:
257297
restore-keys: |
258298
addon-${{ runner.os }}-
259299
260-
- name: Install npm dependencies
300+
- name: Install dependencies
261301
if: steps.cache-npm.outputs.cache-hit != 'true'
262-
run: npm install --no-audit --prefer-offline
302+
run: pnpm install --no-frozen-lockfile --ignore-scripts
263303

264304
- name: Build RocketMQ native deps
265305
if: steps.cache-addon.outputs.cache-hit != 'true'
@@ -282,6 +322,7 @@ jobs:
282322
path: Release/linux-x86_64-musl-rocketmq.node
283323

284324
linux-musl-arm64:
325+
needs: validate
285326
runs-on: ubuntu-24.04-arm
286327
env:
287328
ZIG_TARGET: aarch64-linux-musl
@@ -292,7 +333,13 @@ jobs:
292333
- name: Setup Node.js
293334
uses: actions/setup-node@v4
294335
with:
295-
node-version: 20
336+
node-version: 22
337+
338+
- name: Setup pnpm
339+
uses: pnpm/action-setup@v4
340+
with:
341+
version: 11
342+
run_install: false
296343

297344
- name: Install system dependencies
298345
run: sudo apt-get update && sudo apt-get install -y build-essential cmake ninja-build python3 curl unzip git autoconf automake libtool pkg-config
@@ -316,14 +363,14 @@ jobs:
316363
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
317364
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
318365
319-
- name: Cache npm dependencies
366+
- name: Cache pnpm dependencies
320367
id: cache-npm
321368
uses: actions/cache@v4
322369
with:
323370
path: node_modules
324-
key: npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
371+
key: pnpm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('pnpm-lock.yaml') }}
325372
restore-keys: |
326-
npm-${{ runner.os }}-
373+
pnpm-${{ runner.os }}-
327374
328375
- name: Cache RocketMQ native deps
329376
uses: actions/cache@v4
@@ -345,9 +392,9 @@ jobs:
345392
restore-keys: |
346393
addon-${{ runner.os }}-
347394
348-
- name: Install npm dependencies
395+
- name: Install dependencies
349396
if: steps.cache-npm.outputs.cache-hit != 'true'
350-
run: npm install --no-audit --prefer-offline
397+
run: pnpm install --no-frozen-lockfile --ignore-scripts
351398

352399
- name: Build RocketMQ native deps
353400
if: steps.cache-addon.outputs.cache-hit != 'true'
@@ -370,6 +417,7 @@ jobs:
370417
path: Release/linux-aarch64-musl-rocketmq.node
371418

372419
macos-universal:
420+
needs: validate
373421
runs-on: macos-latest
374422
steps:
375423
- name: Checkout
@@ -378,19 +426,25 @@ jobs:
378426
- name: Setup Node.js
379427
uses: actions/setup-node@v4
380428
with:
381-
node-version: 20
429+
node-version: 22
430+
431+
- name: Setup pnpm
432+
uses: pnpm/action-setup@v4
433+
with:
434+
version: 11
435+
run_install: false
382436

383437
- name: Install build tools
384438
run: brew install cmake ninja xz autoconf automake libtool pkg-config
385439

386-
- name: Cache npm dependencies
440+
- name: Cache pnpm dependencies
387441
id: cache-npm
388442
uses: actions/cache@v4
389443
with:
390444
path: node_modules
391-
key: npm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}
445+
key: pnpm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
392446
restore-keys: |
393-
npm-${{ runner.os }}-
447+
pnpm-${{ runner.os }}-
394448
395449
- name: Cache RocketMQ native deps
396450
uses: actions/cache@v4
@@ -412,9 +466,9 @@ jobs:
412466
restore-keys: |
413467
addon-${{ runner.os }}-
414468
415-
- name: Install npm dependencies
469+
- name: Install dependencies
416470
if: steps.cache-npm.outputs.cache-hit != 'true'
417-
run: npm install --no-audit --prefer-offline
471+
run: pnpm install --no-frozen-lockfile --ignore-scripts
418472

419473
- name: Build RocketMQ native deps
420474
if: steps.cache-addon.outputs.cache-hit != 'true'
@@ -483,10 +537,14 @@ jobs:
483537
- name: Setup Node.js
484538
uses: actions/setup-node@v4
485539
with:
486-
node-version: 20
540+
node-version: 22
487541
registry-url: 'https://registry.npmjs.org'
488-
cache: 'npm'
489-
cache-dependency-path: package-lock.json
542+
543+
- name: Setup pnpm
544+
uses: pnpm/action-setup@v4
545+
with:
546+
version: 11
547+
run_install: false
490548

491549
- name: Download all artifacts
492550
uses: actions/download-artifact@v4
@@ -511,7 +569,7 @@ jobs:
511569
echo "✅ Version consistent: $PKG_VERSION"
512570
513571
- name: Install dependencies (skip native build)
514-
run: npm ci --include=dev --ignore-scripts
572+
run: pnpm install --frozen-lockfile --ignore-scripts
515573
env:
516574
NODE_ENV: development
517575
NPM_CONFIG_PRODUCTION: "false"
@@ -520,11 +578,11 @@ jobs:
520578
run: |
521579
if [ ! -f "node_modules/@types/node/index.d.ts" ]; then
522580
NODE_TYPES_VERSION=$(node -p "require('./package.json').devDependencies['@types/node']")
523-
npm install --no-save --no-package-lock --ignore-scripts "@types/node@${NODE_TYPES_VERSION}"
581+
pnpm add --no-save "@types/node@${NODE_TYPES_VERSION}"
524582
fi
525583
526584
- name: Build TypeScript
527-
run: npm run build:ts
585+
run: pnpm run build:ts
528586

529587
- name: Validate build output
530588
run: |
@@ -557,6 +615,6 @@ jobs:
557615
ls -lh Release/
558616
559617
- name: Publish to npm
560-
run: npm publish --ignore-scripts
618+
run: pnpm publish --no-git-checks --ignore-scripts
561619
env:
562620
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,11 @@ coverage.*.html
220220
dist/
221221
*.tsbuildinfo
222222
*.test.js.map
223+
test/*.js
224+
coverage_output.txt
225+
226+
# Claude Code local session/config
227+
.claude/
228+
229+
# pnpm
230+
pnpm-debug.log

0 commit comments

Comments
 (0)