Skip to content
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

fix: use a short-lived AbortSignal for fetch operations #511

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,20 @@
}

const blockId = this.#uniqueBlockId(cid)

// workaround for https://github.com/nodejs/node/issues/52635
const innerController = new AbortController()
const abortInnerSignal = (): void => {
innerController.abort()
}

Check warning on line 99 in packages/block-brokers/src/trustless-gateway/trustless-gateway.ts

View check run for this annotation

Codecov / codecov/patch

packages/block-brokers/src/trustless-gateway/trustless-gateway.ts#L98-L99

Added lines #L98 - L99 were not covered by tests
signal?.addEventListener('abort', abortInnerSignal)

try {
let pendingResponse: Promise<Uint8Array> | undefined = this.#pendingResponses.get(blockId)
if (pendingResponse == null) {
this.#attempts++
pendingResponse = fetch(gwUrl.toString(), {
signal,
signal: innerController.signal,
headers: {
Accept: 'application/vnd.ipld.raw'
},
Expand All @@ -122,6 +130,7 @@
this.#errors++
throw new Error(`unable to fetch raw block for CID ${cid}`)
} finally {
signal?.removeEventListener('abort', abortInnerSignal)
this.#pendingResponses.delete(blockId)
}
}
Expand Down
Loading