Skip to content

Updated abort behavior #1141

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 7 commits into from
Apr 6, 2020
Merged

Updated abort behavior #1141

merged 7 commits into from
Apr 6, 2020

Conversation

delvedor
Copy link
Member

@delvedor delvedor commented Apr 3, 2020

This pr contains a few feature and fixes:

Features

  • Added support for aborting a request with the promise style API
  • Added RequestAbortedError constructor.

Fixes

  • Until now, aborting a request was blocking the HTTP request, but never calling the callback or resolving the promise to notify the user. This is a bug because it could lead to dangerous memory leaks. From now on if the user calls the request.abort() method, the callback style API will be called with a RequestAbortedError, the promise will be rejected with RequestAbortedError as well.
  • The Connection class wasn't consistent regarding errors, as it could return both Node.js errors or client errors (in case of timeouts). With this pr now it only returns client errors, namely ConnectionError, TimeoutError and RequestAbortedError.

Closes #1070

delvedor added 5 commits April 3, 2020 17:10
- Support for aborting a request with the promise api
- Aborting a request will cause a RequestAbortedError
- Normalized Connection class errors, now every error returned is
wrapped by the client errors constructors
@penge
Copy link

penge commented Apr 4, 2020

I have some general questions. I hope it's fine to ask here :) (or, is there a better channel for this?)

Questions would be:

  1. Is there a particular reason why d.ts files are in repository? More here:

  2. How are d.ts files generated? Are they generated manually?

  3. Why not having tsconfig.json and ts files?

Thanks! :)

@@ -23,6 +27,8 @@ class MockConnection extends Connection {
process.nextTick(() => {
if (!aborted) {
callback(null, stream)
} else {
callback(new RequestAbortedError(), null)
Copy link

Choose a reason for hiding this comment

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

The condition !aborted is in if but its handler is in else.

Better would be to put it together, and at the top, as a guard clause.

if (aborted) {
  callback(new RequestAbortedError(), null)
  return
}

callback(null, stream)

Copy link
Member Author

Choose a reason for hiding this comment

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

Tomayto, tomahto :)
You can read it in both ways, if the operation has not been aborted, then continue, otherwise return a RequestAbortedError error.

Copy link

Choose a reason for hiding this comment

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

Read it, I can. Merge it, we can:)

@delvedor
Copy link
Member Author

delvedor commented Apr 6, 2020

I have some general questions. I hope it's fine to ask here :) (or, is there a better channel for this?)

@penge given that these questions are not related t this pr, I would kindly ask you to open an issue :)

@delvedor delvedor merged commit 27a8e2a into master Apr 6, 2020
@delvedor delvedor deleted the feature-1070 branch April 6, 2020 09:21
@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2020

The backport to 7.x failed:

The process 'git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-7.x 7.x
# Navigate to the new working tree
cd .worktrees/backport-7.x
# Create a new branch
git switch --create backport-1141-to-7.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick 27a8e2a9bf614224a96bf44293ace8a112ec8677
# Push it to GitHub
git push --set-upstream origin backport-1141-to-7.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-7.x

Then, create a pull request where the base branch is 7.x and the compare/head branch is backport-1141-to-7.x.

delvedor added a commit that referenced this pull request Apr 6, 2020
* Updated abort behavior

- Support for aborting a request with the promise api
- Aborting a request will cause a RequestAbortedError
- Normalized Connection class errors, now every error returned is
wrapped by the client errors constructors

* Updated test

* Updated docs

* Updated code generation script

* Renamed test

* Code coverage

* Avoid calling twice transport.request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate the support of aborting request with promies
2 participants