-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize GitHub Activity Fetching with Fail-Fast Concurrency #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -682,12 +682,20 @@ export const fetchActivity = cache(async function fetchActivity( | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const criticalErrorPromise = new Promise<never>((_, reject) => { | ||||||||||||||||||||||||
| promises.forEach((p) => p.catch((e) => { | ||||||||||||||||||||||||
| if (e instanceof UserNotFoundError || e instanceof RateLimitError) { | ||||||||||||||||||||||||
| reject(e); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Suppress unhandled promise rejections for subsequent pages if we break early or throw | ||||||||||||||||||||||||
| promises.forEach((p) => p.catch((e) => logger.error("Event fetch promise rejected:", e))); | ||||||||||||||||||||||||
|
Comment on lines
693
to
694
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/lib/github.ts
Line: 693-694
Comment:
`UserNotFoundError` / `RateLimitError` が不要にエラーログへ出力される問題です。`criticalErrorPromise` 内の `.catch` と、後続の logging `forEach` の `.catch` は**同じ Promise に対して独立して両方とも発火**します。そのため、`UserNotFoundError` や `RateLimitError` が発生すると、caller へ正しく再スローされながらも `logger.error("Event fetch promise rejected:", ...)` にもエラーとして記録され、「想定外のエラー」のように見える誤解を招くノイズになります。ロギング側でクリティカルエラーを除外するか、コメントの意図通り「後続ページの未処理リジェクション抑制」に絞った条件付きログにすることが望ましいです。
```suggestion
// Suppress unhandled promise rejections for subsequent pages if we break early or throw
// クリティカルエラーは呼び出し元へ再スローされるため、ログ出力から除外する
promises.forEach((p) =>
p.catch((e) => {
if (!(e instanceof UserNotFoundError || e instanceof RateLimitError)) {
logger.error("Event fetch promise rejected:", e);
}
})
);
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for (const p of promises) { | ||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||
| const events = await p; | ||||||||||||||||||||||||
| const events = await Promise.race([p, criticalErrorPromise]); | ||||||||||||||||||||||||
| allEvents.push(...events); | ||||||||||||||||||||||||
| if (events.length < 100) break; | ||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
criticalErrorPromiserejects after the loop has already broken early (e.g., because page 1 had fewer than 100 events), the rejection ofcriticalErrorPromisewill occur in the background. To prevent potential unhandled promise rejection warnings in environments with strict rejection tracking, attach a.catch()handler directly tocriticalErrorPromiseimmediately after its creation. Ensure you log the error instead of silently ignoring it to facilitate debugging.References