Add Graceful Shutdown example to fix Nodemon hanging on restarts (EADDRINUSE)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 65/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- express, node.js, typescript
- Ambito
- documentation
Direzione di ricerca
Non è indicato alcun file di destinazione o test; inizia individuando la documentazione ufficiale di configurazione di Express/Turso. Aggiungi l'esempio fornito di graceful shutdown e verifica che spieghi la gestione di SIGINT, SIGTERM e SIGUSR2 e la chiusura della connessione @libsql/client, in modo che Nodemon possa riavviarsi senza EADDRINUSE.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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!
- Lingua principale
- C
- Stelle
- 17.3k
- Fork
- 550
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tursodatabase/libsql
-
bottomless: finished S3 upload tasks are never reaped, so sqld memory grows by ~10 KB per WAL batchForse già presa @pavanmanishd l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
tursodatabase/libsql#2298 · 1 commento ·
-
Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)Forse già presa @Sanjays2402 l’ha presa 12 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
tursodatabase/libsql#2285 ·
-
libsql-ffi: broken builds under Nix on macOSForse già presa @frectonz l’ha presa 62 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
tursodatabase/libsql#2275 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
tursodatabase/libsql#1925 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
tursodatabase/libsql#1892 ·
Tutte le issue di tursodatabase/libsql
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 90/100
Lakr233/vphone-cli#743 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
libsdl-org/SDL#16584 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
FriendsofECCE/ECCE#519 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
containers/crun#2415 ·
I maintainer di solito rispondono entro 1 giorno