Skip to content

feat: add AbortSignal and rename timeouttimeoutMillis in SendRequestOptions#3457

Merged
barjin merged 10 commits intov4from
copilot/add-abortsignal-option-basehttpclient
Mar 10, 2026
Merged

feat: add AbortSignal and rename timeouttimeoutMillis in SendRequestOptions#3457
barjin merged 10 commits intov4from
copilot/add-abortsignal-option-basehttpclient

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

SendRequestOptions lacked an AbortSignal option, preventing users from passing custom cancellation signals to BaseHttpClient. The timeout field also didn't follow the repo convention of using timeoutMillis.

Changes

  • @crawlee/typesSendRequestOptions: renamed timeouttimeoutMillis, added signal?: AbortSignal
  • @crawlee/http-clientBaseHttpClient: updated to use timeoutMillis; when both signal and timeoutMillis are provided, combines them via AbortSignal.any()
  • @crawlee/basic-crawler, @crawlee/http-crawler, @crawlee/utils — updated all call sites to use timeoutMillis
  • test/core/base-http-client.test.ts — added tests covering custom signal propagation, signal + timeoutMillis combination, and timeout-based abort

Usage

const response = await httpClient.sendRequest(request, {
    timeoutMillis: 10_000,
    signal: myAbortController.signal,
});

When both are supplied, the request is aborted on whichever fires first.

Original prompt

This section details on the original issue you should resolve

<issue_title>v4: add AbortSignal option to the BaseHttpClient interface</issue_title>
<issue_description>Adding AbortSignal option to the BaseHttpClient interface would allow users to pass their custom signal to the HttpClient (alongside the timeout, which should be renamed to timeoutMillis to follow the best practices in this repo).</issue_description>

<agent_instructions>Make minimal changes to achieve the goal described in the issue. do not add excessive comments (but add TSdocs for public interfaces you add). use conventional commits for commit messages and PR title.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add AbortSignal option to BaseHttpClient interface feat: add AbortSignal and rename timeouttimeoutMillis in SendRequestOptions Feb 27, 2026
@barjin barjin requested a review from Copilot February 27, 2026 15:31
@barjin barjin marked this pull request as ready for review February 27, 2026 15:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for custom AbortSignal cancellation to the HTTP client layer and renames the timeout parameter to timeoutMillis to align with the repository's established naming conventions. The changes address the lack of a mechanism for users to pass custom cancellation signals to BaseHttpClient, while also improving consistency across the codebase.

Changes:

  • Added signal?: AbortSignal field to SendRequestOptions interface with TSDoc
  • Renamed timeouttimeoutMillis in SendRequestOptions to follow the established Millis suffix convention used throughout the codebase
  • Implemented AbortSignal.any() to combine custom signals and timeout-based signals, ensuring requests abort on whichever fires first
  • Updated all call sites across @crawlee/basic-crawler, @crawlee/http-crawler, and @crawlee/utils to use the new parameter name

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/types/src/http-client.ts Added signal field and renamed timeouttimeoutMillis in SendRequestOptions interface with documentation
packages/http-client/src/base-http-client.ts Updated createAbortSignal to accept and combine both signal and timeout; refactored resolveRequestContext to return signal instead of timeout
packages/basic-crawler/src/internals/send-request.ts Updated to pass both timeoutMillis and signal from override options
packages/http-crawler/src/internals/http-crawler.ts Updated call site to use timeoutMillis parameter name
packages/utils/src/internals/sitemap.ts Updated call site to use timeoutMillis parameter name
packages/utils/test/mock-http-client.ts Updated mock implementation to use timeoutMillis parameter name

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@nikitachapovskii-dev nikitachapovskii-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for a late review 🙂
Please check the nits, hope they are useful

const cookieJar = options?.cookieJar ?? options?.session?.cookieJar ?? new CookieJar();
const timeout = options?.timeout;
return { proxyUrl, cookieJar: cookieJar as CookieJar, timeout };
const signal = this.createAbortSignal(options?.signal, options?.timeoutMillis);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the timeout behavior changed with this refactor. Previously, the timeout signal was created inside the redirect loop (per fetch attempt). Now the signal is created once before the loop and reused across all redirects
If I don't miss smth, this can lead to cases, when redirect chains that used to pass (each hop under timeout) may now fail if cumulative time exceeds timeoutMillis.

If this is not expected, we should create the timeout signal per iteration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that this behaviour is more straightforward (user sets timeoutMillis as a sendRequest param, so they expect the sendRequest call to take up to this time).

I'm not sure how this worked before (it was probably implementation-specific), so this is imo a step forward (in v4 nonetheless, as we can afford breaking changes like this). Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a reasonable v4 direction, and I’m okay with keeping it 👍

Copilot AI and others added 5 commits March 6, 2026 14:01
…endRequestOptions

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
…Client

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
…ndRequestOptions`

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
@barjin barjin force-pushed the copilot/add-abortsignal-option-basehttpclient branch from 0f928f8 to 3a5a416 Compare March 6, 2026 13:01
@barjin barjin merged commit 2a6b2da into v4 Mar 10, 2026
6 checks passed
@barjin barjin deleted the copilot/add-abortsignal-option-basehttpclient branch March 10, 2026 15:23
B4nan pushed a commit that referenced this pull request Mar 16, 2026
…ndRequestOptions` (#3457)

`SendRequestOptions` lacked an `AbortSignal` option, preventing users
from passing custom cancellation signals to `BaseHttpClient`. The
`timeout` field also didn't follow the repo convention of using
`timeoutMillis`.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
Co-authored-by: Jindřich Bär <jindrichbar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants