Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Ctrl+C does not stop the dev server: raw mode suppresses SIGINT and close() never exits the process

未关闭
#98 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
领域
cli, devtools

调研方向

从 ShortcutsManager.setup()、#handleKeyPress() 和 DevServer.close() 开始,然后使用 node ace serve --watch 重现该问题。跟踪退出快捷键以及 watcher/server 的清理;当 Ctrl+C 返回 shell 提示符且不留下孤立的 dev-server 进程时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Status: Awaiting More Information

Summary

With node ace serve --watch, pressing Ctrl+C does not stop the dev server. The terminal stays wedged and the only way out is closing the terminal tab, which leaves orphaned node ace serve --watch processes re-parented to init (ppid=1).

Crucially, pressing Ctrl+C repeatedly (quickly or slowly) has no effect either, because in this state no signal is ever generated — so there is no default-terminate fallback to rely on.

Steps to reproduce

  1. node ace serve --watch
  2. Wait for watching file system for changes...
  3. Press Ctrl+C

Expected: the dev server shuts down and the shell prompt returns.

Actual: ^C is echoed, nothing else happens. The process keeps running. Closing the terminal tab leaves the server running in the background.

Analysis

ShortcutsManager.setup() puts stdin into raw mode so it can implement the r/c/o/h shortcuts:

setup() {
  if (!process.stdin.isTTY) return;
  process.stdin.setRawMode(true);
  this.#keyPressHandler = (data) => this.#handleKeyPress(data.toString());
  process.stdin.on("data", this.#keyPressHandler);
}

Raw mode clears ISIG, so the terminal no longer translates Ctrl+C into SIGINT. The keypress is instead delivered as a raw byte and handled explicitly:

#handleKeyPress(key) {
  if (key === "\x03" || key === "\x04") return this.#callbacks.onQuit();
  ...
}

onQuit is () => this.close(), and DevServer.close() is:

async close() {
  this.#cleanupKeyboardShortcuts();
  await this.#watcher?.close();
  if (this.#httpServer) {
    this.#httpServer.removeAllListeners();
    this.#httpServer.kill("SIGKILL");
  }
}

close() never calls process.exit() — it relies on the event loop draining naturally. If anything still holds a referenced handle in the parent process (or close() itself does not settle), the process simply never exits. And because raw mode has suppressed SIGINT, the usual safety net — the OS killing the process on a second Ctrl+C — is gone.

Note removeAllListeners() is called on the child immediately before kill("SIGKILL"), which also removes the exit/close listeners that would normally let the parent observe and reap it.

Not fixed by upgrading

I diffed the published builds: ShortcutsManager.setup, #handleKeyPress and DevServer.close() are byte-identical in 8.0.0 (what we run) and 8.4.0 (current latest), so this is not a regression that a version bump resolves.

Workaround

Making stdin a non-TTY causes setup() to return before enabling raw mode, which restores normal terminal signal handling:

// package.json
"dev": "node ace serve --watch < /dev/null"

Ctrl+C then works as expected. The cost is losing the keyboard shortcuts, so we keep the original as a second script for anyone who wants them.

Worth noting for others hitting this: if your app registers its own SIGINT handler (job runners commonly do, to drain in-flight work), you may need to disable that in development too — otherwise the restored signal is trapped by the child instead.

Suggested fix

Guarantee the process actually exits on the quit shortcut, e.g. await this.close() then process.exit(0) in the onQuit path; or restore raw mode and re-raise SIGINT (process.kill(process.pid, 'SIGINT')) so normal signal semantics apply. Either would also make a second Ctrl+C effective as a fallback.

Environment

@adonisjs/assembler 8.0.0 (behaviour confirmed unchanged in 8.4.0)
@adonisjs/core 7.3.1
Node v24.14.0
npm 11.9.0
OS macOS 26.3 (arm64)

Happy to test a patch or open a PR if the suggested direction looks right.

主要语言
TypeScript
星标
40
派生
24
平均合并
4 天 10 小时
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

adonisjs/assembler 的其他 Issue

查看 adonisjs/assembler 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。