Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: post request signal #3354

Merged
merged 1 commit into from
Jun 22, 2024
Merged

Conversation

Gigioliva
Copy link
Contributor

@Gigioliva Gigioliva commented Jun 21, 2024

Fix post request abort signal

Fix issue #3353

Rationale

Request API doesn't remove the signal listener after complete the request

Changes

Remove abort listener after success

Status

@@ -36,9 +36,11 @@ test('post abort signal', async (t) => {

server.listen(0, async () => {
const ac = new AbortController()
const ures = await request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal })
const uresPromise = request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ this test was wrong because request api terminates when the stream has been completely consumed, so the connection has been closed. If we postpone the await we can throw the abort before dispatch starts consuming the stream, so the request is actually aborted

Comment on lines +92 to +94
const ures = await request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal })
ac.abort()
t.equal(await ures.body.text(), 'asd')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ in this case the abort signal is ignored since the request is completed

Copy link
Member

Choose a reason for hiding this comment

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

Since these are modeled after the fetch body mixins, I'm wondering if they should throw. In the fetch spec, if a request was aborted and you attempt to read the body, it'll throw an error. @ronag wdyt?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

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

makes kind of sense

RSLGTM

@mcollina mcollina merged commit a5eac88 into nodejs:main Jun 22, 2024
30 checks passed
ronag added a commit that referenced this pull request Jun 22, 2024
ronag added a commit to nxtedition/undici that referenced this pull request Jun 25, 2024
* upstream/main:
  fix: use explicit flag for when use has interacted with stream (nodejs#3361)
  refactor: simplify signal handling (nodejs#3362)
  fix: consider bytes read when dumping (nodejs#3360)
  websocket: don't use pooled buffer in mask pool (nodejs#3357)
  Revert "fix: post request signal (nodejs#3354)" (nodejs#3359)
  fix: post request signal (nodejs#3354)
  build(deps): bump node from `075a5cc` to `9af472b` in /build (nodejs#3355)
@uriva
Copy link

uriva commented Nov 7, 2024

Hey, how can I add this fix to my nodejs? (I'm running latest and it's not there iiuc)

@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants