Skip to content

http.IncomingMessage omits events when aborted on client side  #7732

@skenqbx

Description

@skenqbx
  • Version: 6.3.0
  • Platform: Linux offline 3.19.0-64-generic Is V8 the best JS engine today? #72-Ubuntu SMP Fri Jun 24 15:12:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: http

When a HTTP client sends a partial body and is then aborted, the corresponding server request object does not emit end, close or aborted events. Only a clientError is emitted on the server.

I looked at the existing tests concerning request abortion and it seems this is the only case that is untested.

The following code reproduces the problem:

'use strict';
const http = require('http');


const server = http.createServer((request, response) => {
  console.log('server request');

  request.on('aborted', () => console.log('server request aborted'));
  request.on('error', (err) => console.log('server request error', err));

  request.on('readable', () => console.log('server request readable', request.read()));
  request.on('end', () => console.log('server request end'));

  request.on('close', () => {
    console.log('server request close');
    server.close();
  });
});

server.on('clientError', (err) => {
  console.log('server clientError', err);
});

server.listen(0, () => {
  const port = server.address().port;

  const request = http.request({
    port: port,
    path: '/',
    method: 'PUT'
  }, (response) => console.log('client response'));

  request.on('abort', () => console.log('client abort'));
  request.on('error', (err) => console.log('client error', err));

  request.write('Test');

  setTimeout(() => {
    request.abort();
  }, 100);
});

The output shows that the readable stream (request) is left waiting for the end event

server request
server request readable <Buffer 54 65 73 74>
client abort
server clientError { Error: Parse Error
    at Error (native)
    at Socket.socketOnEnd (_http_server.js:422:22)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:973:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9) bytesParsed: 0, code: 'HPE_INVALID_EOF_STATE' }
client error { Error: socket hang up
    at createHangUpError (_http_client.js:252:15)
    at Socket.socketCloseListener (_http_client.js:284:23)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:492:12) code: 'ECONNRESET' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions