loopbackio / loopbackio/loopback-next

Database connect error during app boot should not terminate node process

Đang mở
#8,639 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug Repository
Ngôn ngữ chính
TypeScript
Star
5.1k
Fork
1.1k
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
27

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các đường dẫn datasource.connect() và datasource.execute() được mô tả trong phần tái hiện, bao gồm việc sử dụng chúng trong quá trình khởi động ứng dụng và từ ví dụ về controller. Tái hiện kết nối MySQL không hợp lệ với lazyConnect được bật, sau đó xác minh rằng các lỗi khi khởi động và ở cấp controller được xử lý mà không kết thúc tiến trình Node hoặc để yêu cầu ở trạng thái chưa được giải quyết.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
mysql, nodejs, typescript
Lĩnh vực
api, backend, database
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.