Add Graceful Shutdown example to fix Nodemon hanging on restarts (EADDRINUSE)
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 65/100
- issue の種類
- ドキュメント
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- express, node.js, typescript
調査の方向性
対象ファイルもテストも指定されていないため、まず Express/Turso の公式セットアップドキュメントを見つけてください。提供された graceful-shutdown の例を追加し、SIGINT、SIGTERM、SIGUSR2 の処理と @libsql/client 接続のクローズについて説明していることを確認してください。これにより、Nodemon が EADDRINUSE なしで再起動できるようにします。
索引モデルが issue の本文から書いたものです。
説明
Hello! I am a beginner using Turso with Express and Nodemon, and I recently ran into a very frustrating issue that took me a while to figure out.
I'm opening this issue as a documentation request because I think adding a small note about this could save other developers a lot of time!
The Problem I Faced 🐛
Whenever I saved a file, nodemon would attempt to restart my Express server, but it would fail or my new routes wouldn't show up. I was getting errors like:
Cannot GET /my-new-route(the server was stuck on the old code)EADDRINUSE: address already in use :::3000
It turns out that @libsql/client holds an active, persistent socket connection. When nodemon sends the restart signal (SIGUSR2), Node.js refuses to exit because the database connection is still keeping the event loop alive. This leaves the old server running as a "zombie" process holding port 3000.
The Solution 🛠️
I finally figured out that I needed to explicitly call tursoClient.close() inside a graceful shutdown handler so nodemon could clean up and restart properly.
Since this is such a common trap when setting up local development, could we add a small snippet about 'Graceful Shutdowns' to the official documentation?
Here is the solution code that worked perfectly for me, which might be helpful to add to the docs:
import express from "express";
import { createClient } from "@libsql/client";
const app = express();
const PORT = process.env.PORT || 3000;
export const tursoClient = createClient({
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
});
const server = app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
// Graceful shutdown — close turso connection so nodemon can restart cleanly
const shutdown = async () => {
console.log("Shutting down gracefully...");
tursoClient.close();
server.close(() => {
process.exit(0);
});
};
// Handle Ctrl+C
process.on("SIGINT", shutdown);
// Handle Docker/System shutdown
process.on("SIGTERM", shutdown);
// Handle Nodemon restarts
process.once("SIGUSR2", async () => {
await shutdown();
});
Thank you for the amazing database!
- 主要言語
- C
- スター
- 17.3k
- フォーク
- 550
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tursodatabase/libsql のほかの issue
-
bottomless: finished S3 upload tasks are never reaped, so sqld memory grows by ~10 KB per WAL batch対応中かも @pavanmanishd が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
tursodatabase/libsql#2298 · コメント 1 件 ·
-
Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)対応中かも @Sanjays2402 が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
tursodatabase/libsql#2285 ·
-
libsql-ffi: broken builds under Nix on macOS対応中かも @frectonz が 64 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
tursodatabase/libsql#2275 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
tursodatabase/libsql#1925 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
tursodatabase/libsql#1892 ·
tursodatabase/libsql の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
yunusemreyl/omen-space#337 ·
メンテナーはふだん 1 日以内に返信
-
dependency component: oneMKL module: dpclang
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
intel/torch-xpu-ops#5880 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
area/ci-build bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
DarkFlippers/qUnleashed#423 ·
メンテナーはふだん 1 日以内に返信