loopbackio / loopbackio/loopback-next

Database connect error during app boot should not terminate node process

オープン
#8,639 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug Repository
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

### 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

再現手順で説明されている datasource.connect() と datasource.execute() のパスから始め、アプリケーションの起動時および controller の例からそれらが使用される場合も含めて確認します。lazyConnect を有効にした無効な MySQL 接続を再現し、その後、起動時および controller レベルの失敗が、Node プロセスを終了させたりリクエストを未解決のままにしたりせずに処理されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
mysql, nodejs, typescript
領域
api, backend, database
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。