loopbackio / loopbackio/loopback-next
Database connect error during app boot should not terminate node process
Personne n'a encore pris cette issue.
- Langage dominant
- TypeScript
- Étoiles
- 5.1k
- Forks
- 1.1k
- Merge moyen
- 2 j 21 h
- PR mergées (30 j)
- 27
Description
### Describe the bug
### Steps to repro:
1. Scaffold new app (lb4 app)
2. Scaffold new mysql data source (lb4 datasource). Enter invalid connection info, so that the connection fails during boot.
3. 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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par les chemins datasource.connect() et datasource.execute() décrits dans la reproduction, y compris leur utilisation lors du démarrage de l’application et depuis l’exemple de contrôleur. Reproduisez la connexion MySQL invalide avec lazyConnect activé, puis vérifiez que les échecs au démarrage et au niveau du contrôleur sont gérés sans terminer le processus Node ni laisser la requête non résolue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- mysql, nodejs, typescript
- Domaine
- api, backend, database
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100