`fetchEventSource` doesn't abort when passing in an already aborted signal
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- api
調査の方向性
Issue に示されている fetchEventSource の実装から始め、すでに abort された AbortController シグナルでこのケースを再現します。リクエストが直ちに abort され、abort エラーで reject されることを確認してから、該当するテストの場所を特定できる場合は、この動作のカバレッジを追加または更新します。
索引モデルが issue の本文から書いたものです。
説明
Javascript's default fetch rejects with an AbortError when passing an already aborted signal:
const controller = new AbortController()
controller.abort()
await fetch("https://google.com", { signal: controller.signal })
Uncaught:
DOMException [AbortError]: This operation was aborted
at node:internal/deps/undici/undici:13392:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async REPL17:1:33
However, when using fetch-event-source it fails to detect that the signal is already aborted:
const controller = new AbortController()
controller.abort()
await fetchEventSource("https://any-website-supporting-sse.com", { signal: controller.signal })
// the call above is never aborted
This doesn't abort the fetch.
The reason is that fetchEventSource creates a new aborter and subscribes to the original signal's abort event to then abort its own controller, but the abort event does not trigger retroactively (i.e. if the signal is already aborted). Here's the relevant snippet from the fetchEventSource implementation:
let curRequestController: AbortController;
function dispose() {
// ...
curRequestController.abort();
}
inputSignal?.addEventListener('abort', () => {
// this callback is not called if the inputSignal is already aborted!
// hence, curRequestController is not aborted
dispose();
resolve();
});
async function create() {
curRequestController = new AbortController();
try {
const response = await fetch(input, {
...rest,
headers,
signal: curRequestController.signal,
});
// ...
} catch (err) {
if (!curRequestController.signal.aborted) {
// ...
}
}
};
I patched it locally as follows:
inputSignal?.addEventListener('abort', () => {
dispose();
// no longer resolving the promise here
// because 1) we should reject instead of resolve when aborted
// and 2) dispose() will abort the curRequestController.signal
// which will cause the ongoing fetch request to throw an AbortError
// which we will catch and then we will reject the promise with the error
});
async function create() {
curRequestController = new AbortController();
// use the input signal if it is already aborted
const sig = inputSignal.aborted ? inputSignal : curRequestController.signal
try {
const response = await fetch(input, {
...rest,
headers,
signal: sig,
});
// ...
} catch (err) {
if (sig.aborted) {
dispose();
reject(err);
} else if (!curRequestController.signal.aborted) {
// ...
}
}
};
- 主要言語
- TypeScript
- スター
- 2.9k
- フォーク
- 197
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Azure/fetch-event-source のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 28/100
Azure/fetch-event-source#102 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
Azure/fetch-event-source#101 · コメント 3 件 ·
-
When aborting the event source using abort controller, no callbacks (onError / onClose) are firedオープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
Azure/fetch-event-source#100 · コメント 1 件 · リアクション 5 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
Azure/fetch-event-source#99 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
Azure/fetch-event-source#97 · コメント 1 件 ·
Azure/fetch-event-source の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
zts212653/clowder-ai#1678 ·
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
Progressive-Victory/the-website#680 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100