+
Skip to content

DX-1938: update signal parameter to accept function #1379

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

Merged
merged 2 commits into from
Jun 24, 2025

Conversation

CahidArda
Copy link
Contributor

@CahidArda CahidArda commented Jun 20, 2025

Currently, there is a signal parameter which accepts an AbortSignal but this has two limitations which make configuring request timeout not feasible:

  1. If a request gets timeout, the signal.aborted field becomes true, and it stays true in subsequent requests as the object remains the same.
  2. When we get a timeout, in the request method of HttpClient, a Response object is created with status 200. So the request method never throws an error. The response is simply null.

Did the following to fix the issue:

  • Made it possible to pass an AbortSignal creator function as signal.
  • When this is done, we simply throw the error which can be cought like this:
const redis = new Redis({
  url: "***",
  token: "***",
  signal: () => AbortSignal.timeout(500),
});

try {
  const count = await redis.hset("myhash", {
    key: null,
  });
} catch (error) {
  if (error instanceof Error && error.name === "TimeoutError") {
    console.error("Timeout: It took more than 500 ms to get the result!");
  }
}

Copy link

linear bot commented Jun 20, 2025

@alitariksahin
Copy link

same here as the vector.js equivalent, can you add the related tests

@CahidArda CahidArda merged commit a8baa38 into main Jun 24, 2025
14 checks passed
@CahidArda CahidArda deleted the DX-1938-signal-abort branch June 24, 2025 14:52
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.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载