`node ace codegen` never exits when a preloaded module opens a Redis connection (warmup mode skips provider shutdown)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- node.js, redis, typescript
調査の方向性
Start at node ace codegen and trace its warmup boot and termination path, especially Application.terminate() and provider shutdown; the issue does not name source or test files. Reproduce with a preloaded module that opens a Redis connection, then inspect whether the process exits after Codegen files generated. Done means codegen exits successfully in this case without leaving the Redis socket open.
索引モデルが issue の本文から書いたものです。
説明
Package version
7.5.0
Describe the bug
Package version
@adonisjs/core7.5.0@adonisjs/application9.1.0@adonisjs/assembler8.5.1@adonisjs/lock2.1.0@adonisjs/limiter3.0.1@adonisjs/redis10.0.2 (ioredis 5.11.1)- Node.js 24.18.0, Linux
Describe the bug
node ace codegen writes every file, prints Codegen files generated, and then never exits. Nothing is logged; it just stays open until killed.
Codegen boots the app in warmup mode. Application.terminate() skips provider shutdown in any mode other than run:
// @adonisjs/application build, terminate()
if (this.#mode === "run") await this.#providersManager.shutdown(true);
else debug_default("skipping providers shutdown in \"%s\" mode", this.#mode);
So the @adonisjs/redis provider never closes its connections. Any Redis connection opened while the routes and preloads are imported keeps the event loop alive for good.
In our app, two common patterns open that connection during warmup:
-
Importing
@adonisjs/lock/services/main. Its module body resolves the manager inapp.booted:await app.booted(async () => { lockManager = await app.container.make("lock.manager"); });lock.managerresolves every configured store (Promise.alloverconfig.stores), so astores.redis({})entry connects to Redis even when it isn't the default store and no lock is ever acquired. -
Module-level
limiter.use({...})in a service. This creates the Redis store, and with it the connection, at import time.
Trace of the lingering handle, captured by patching Redis.prototype.connect:
at new Redis (ioredis/built/Redis.js:78:18)
at new RedisConnection (@adonisjs/redis/build/redis_manager-*.js:1206:23)
at RedisManager.connection (@adonisjs/redis/build/redis_manager-*.js:1471:146)
at Object.resolver (@adonisjs/lock/build/index.js:21:52)
at async @adonisjs/lock/build/providers/lock_provider.js:11:46
at RedisManager.connection (@adonisjs/redis/build/redis_manager-*.js:1471:146)
at Object.redis (@adonisjs/limiter/build/chunk-*.js:867:66)
at LimiterManager.use (@adonisjs/limiter/build/chunk-*.js:718:63)
at <anonymous> (app/services/segment_calculation_service.ts:13:36)
process.getActiveResourcesInfo() after codegen finishes: ["PipeWrap", "PipeWrap", "TCPSocketWrap"]. The TCPSocketWrap is the ioredis socket.
Reproduction
-
Fresh app with
@adonisjs/redisand@adonisjs/lockconfigured with a Redis store (stores.redis({})), and Redis running. -
Add a service that imports the lock service at the top level, and make it reachable from routes (e.g. through a controller that
#start/routesimports):import lock from '@adonisjs/lock/services/main' export default class FooService { run() { return lock.createLock('foo').run(async () => {}) } } -
Run
node ace codegen.
Expected: the process exits after Codegen files generated.
Actual: the process hangs indefinitely.
The same thing happens with a module-level const l = limiter.use({ requests: 10, duration: '1 minute' }) and a Redis limiter store.
Workaround
Gate the Redis store by mode in the config files:
// config/lock.ts
get stores() {
return {
redis: app.getMode() === 'run' ? stores.redis({}) : stores.memory(),
memory: stores.memory(),
}
},
// config/limiter.ts
get stores() {
return {
redis:
app.getMode() === 'run'
? stores.redis({})
: configProvider.create(async () => stores.memory({})),
memory: stores.memory({}),
}
},
Suggested fix
Skipping provider shutdown in warmup makes sense, but a silent hang is hard to debug. Either of these would help:
- Have the
codegencommand exit explicitly once generation succeeds (it is a one-shot command, and nothing should outlive it). - Or, after warmup, log a warning naming the handles still open, pointing to the "don't open connections during warmup" guidance.
Separately, @adonisjs/lock could resolve stores lazily (on first use()), so that importing services/main does not connect to non-default Redis stores. Happy to open that one on the lock repo too if it's useful.
Reproduction repo
No response
- 主要言語
- TypeScript
- スター
- 19.2k
- フォーク
- 670
- 平均マージ
- 4日 9時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
adonisjs/core のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
`node ace test` prints `PASSED` and never exits while anything is still holding the event loop openオープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
-
Barrel file not using custom `directories`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンType: Enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
-
Request logger再び着手できるかも @thetutlage が 172 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンType: Feature Request
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
prime-radiant-inc/evener#5901 ·
メンテナーはふだん 1 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
Bug: Batcher binds the texture that opens a new batch twice (one draw call per element with maxBatchableTextures = 1)対応中かも @darzarzycki が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 2 日以内に返信
-
area:study-data p2-high ready-for-agent type:chore
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fderuiter/deruiter.dev#3706 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
nicobailon/pi-subagents#3242 ·
メンテナーはふだん 1 日以内に返信