[REQUEST] Detect and report infinite loops / recursive or self-referential data loading
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
- Lĩnh vực
- backend
Hướng nghiên cứu
Bắt đầu với luồng DataLoader.load và hành vi của hàm batch được thể hiện trong hai ví dụ. Tái hiện cả load tự tham chiếu và trường hợp phụ thuộc trong cùng một batch, sau đó xác định cách có thể báo cáo chúng mà không thay đổi hành vi tải thông thường. Hoàn thành khi các trạng thái treo này tạo ra cảnh báo hoặc lỗi hữu ích giúp xác định mối quan hệ load gây ra vấn đề.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
If you accidentally create a self-referential DataLoader load, the loader silently creates a loop of promises which never resolve. This is obviously a programmer error, but it can be pretty hard to diagnose when things just silently don't work, if the recursive load isn't obvious across a complex codepath.
This code demonstrates the issue:
import DataLoader from 'dataloader';
const dumbDataLoader = new DataLoader(
async nums => await Promise.all(nums.map(async n => await dumbDataLoader.load(n)))
);
console.log(await dumbDataLoader.load(3))
I'd expect to get some sort of warning or error from DataLoader to try to pin down the issue, but instead I only get this warning from Node (which in practise won't pop up for a more complex server):
Warning: Detected unsettled top-level await at index.js:7
console.log(await doubleDataLoader.load(3))
Worse, a variation of this can pop up even when the loads are technically not infinitely recursive, since you can have one batch waiting on a result from the same batch. Consider this code:
import DataLoader from 'dataloader';
const factDataLoader = new DataLoader(
async nums => await Promise.all(nums.map(async n => {
if (n == 0) return 1;
return n * (await factDataLoader.load(n - 1));
}))
);
// This works:
console.log(await factDataLoader.load(0));
console.log(await factDataLoader.load(1));
factDataLoader.clearAll();
// This does not:
console.log(await Promise.all([
factDataLoader.load(0),
factDataLoader.load(1),
]));
That isn't actually infinitely recursive, but because 0 and 1 end up in the same batch, and 1 depends on 0, and the result of 0 can't get to the computation around 1 because they're waiting on the same batch... this ends up hanging too. This is basically the same issue, but it's really hard to debug!
This example might look contrived, but this hit me in real-world code. My data loaders do data fetching and complex privacy checks. I have arbitrarily-nested posts, and you can only see a post if you can load the post's parent. If you try to load a post and its parent in the same batch of a data loader, it hangs without any error or warning!
- Ngôn ngữ chính
- JavaScript
- Star
- 13.4k
- Fork
- 522
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của graphql/dataloader
-
[BUG] `maxBatchSize: NaN` is accepted and silently disables batchingCó thể đã có người làm @RaphaelFakhri đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
graphql/dataloader#405 ·
-
Failed batch evicts a replacement cache entry after clear/primeCó thể đã có người làm @Claire-ovo đã nhận 12 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
graphql/dataloader#403 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
graphql/dataloader#393 ·
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
graphql/dataloader#379 · 2 bình luận · 5 reaction ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
graphql/dataloader#377 · 1 bình luận · 1 reaction ·
Tất cả issue của graphql/dataloader
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
obsidianmd/obsidian-help#1169 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[docs] RELEASE.md: wrong branch name, no check that the prepare PR merged with the right subject, manual publish stepCó thể đã có người làm @albertteoh đã nhận hôm nay. Đang mởdocumentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
jaegertracing/jaeger-ui#4739 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
keepassxreboot/keepassxc-browser#3159 · 1 bình luận ·
-
Add: ESP 2 RSĐang mởapproved check:passed feeds:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100