Receiving data after abort #336

Closed
Shogun147 opened this Issue Oct 7, 2012 · 9 comments

Comments

Projects
None yet
3 participants

Hi,

I'm using the request as follows:

request({ url: url }).on('response', function(response) {
  // do some sync checks
  // if not ok then this.abort();
}).on('data', function(chunk) {
  // check chunk length ...
}).on('end', function() {
  //...
});

So if i aborted the request then the data event still emits once.

Is this expected thing? i can check the this._aborted on 'data' and ignore that chunk, but why that event is emitted?

So nothing about this?

Owner

mikeal commented Jan 20, 2013

it should be suppressed, this is a bug.

Owner

mikeal commented Aug 27, 2014

Is this still an issue?

This is so old I'm closing, if it is actually still an issue just let me know and I'll re-open.

mikeal closed this Aug 27, 2014

jacktuck commented Mar 30, 2017 edited

Think this has regressed @mikeal

If you have gzip=true you still get data emitted after an abort

request@2.81.0
node@v7.7.3

var request = require('request')
var debug = require('debug')

var req = request.get({
  url: 'https://google.com',
  gzip: true
})

var debug = require('debug')('test')

var ran = 0
req.on('data', (data) => {
  debug('GOT DATA')

  debug('IS ABORTED', req._aborted)

  if (++ran === 1) req.abort()
})

req.on('abort', () => debug('GOT ABORT!'))

req.on('end', () => debug('GOT END'))

Stdout with gzip=true

test GOT DATA +0ms
test IS ABORTED undefined +1ms
test GOT ABORT! +1ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +1ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +1ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +1ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +0ms
test IS ABORTED true +0ms
test GOT DATA +1ms
test IS ABORTED true +0ms
test GOT END +1ms

Stdout with gzip=false

test GOT DATA +0ms
test IS ABORTED undefined +1ms
test GOT ABORT! +1ms
test GOT END +1ms

Is this expected?

Owner

mikeal commented Mar 30, 2017

If it's only happening w/ gzip that's a different bug, but a valid one. Should be logged as a new bug though.

jacktuck commented Mar 30, 2017 edited

@mikeal Want me to make a new bug for it? And yeah only with gzip.

Owner

mikeal commented Mar 30, 2017

@jacktuck yes please :)

jacktuck commented Mar 31, 2017 edited

@mikeal No problem. Created it #2620

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment