loopbackio / loopbackio/loopback-next
Database connect error during app boot should not terminate node process
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 5.1k
- Fork
- 1.1k
- Merge medio
- 2g 21h
- PR unite (30g)
- 27
Descrizione
Describe the bug
Steps to repro:
- Scaffold new app (lb4 app)
- Scaffold new mysql data source (lb4 datasource). Enter invalid connection info, so that the connection fails during boot.
- Build and run the app
Expected:
Server starts successfully, and /ping endpoint may be ran.
Actual:
Server fails to boot and the process terminates
Alternative with lazy connect:
If "lazy connect" is enabled on the data source config, and a manual datasource.connect() is made later on, the error will cause an unhandled exception to crash the node server. Be aware that trying to run datasource.execute() directly without a connected data source will return a promise that will never resolve until a connection is made.
Note that this occurs even if the call is wrapped in a try/catch.
Further, normal crud repository fetchers, which internally queue the connect, are unaffected.
example:
{
...other datasource props,
lazyConnect: true
}
@get('/test')
async test() {
try {
//execute will only queue, if not connected, causing an infinite wait
if (!this.dataSource.connected)
await this.dataSource.connect();
//execute custom sql
await this.dataSource.execute("select 1");
return true;
} catch(ex) {
return false;
}
}
Use Case:
Health check endpoints that check if parts of the application are online, including the database.
It is vital that the api continue to run, even if a dependency is unavailable. If a datasource.execute() or datasource.connect() fails inside a controller method, then it should not tear down the server with it!
Cli Version: 3.2.0
Logs
No response
Additional information
No response
Reproduction
repro provided above
Guida per i contributori
Apri 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.
Direzione di ricerca
Inizia con i percorsi datasource.connect() e datasource.execute() descritti nella riproduzione, incluso il loro utilizzo durante l’avvio dell’applicazione e dall’esempio del controller. Riproduci la connessione MySQL non valida con lazyConnect abilitato, quindi verifica che gli errori durante l’avvio e a livello del controller siano gestiti senza terminare il processo Node né lasciare la richiesta irrisolta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- mysql, nodejs, typescript
- Ambito
- api, backend, database
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100