Skip to content

http: missing close after finish #27480

Description

@ronag

Node 10.13

const http = require('http')
const send = require('send')

const server = http
  .createServer(async (req, res) => {
    send(req, '/Users/ronagy/Desktop/old/AFT2/Start_060918_40.mov')
      .on('error', err => console.error(err))
      .pipe(res)
      .on('error', err => console.error(err))
      .on('finish', () => console.log('finish'))
      .on('close', () => console.log('close'))
  })

server.listen(9000, () => {
  http.request({
    method: 'GET',
    hostname: '0.0.0.0',
    port: 9000
  }).on('response', res => {
    res.on('data', buf => {
      // drain
    })
  }).end()
})

Would expect it to print 'finish' and then 'close'.

Activity

  1. changed the title [-]missing close after finish[/-] [+]http: missing close after finish[/+] on Apr 29, 2019
  2. ronag commented on Apr 29, 2019

    @ronag
    MemberAuthor

    A bit more nodejs testy:

    const http = require('http')
    const send = require('send')
    
    const server = http
      .createServer(common.mustCall((req, res) => {
        send(req, '/Users/ronagy/Desktop/old/AFT2/Start_060918_40.mov')
          .pipe(res)
          .on('finish', common.mustCall())
          .on('close', common.mustCall());
      }));
    
    server.listen(9000, common.mustCall(() => {
      http.get({ port: server.address().port }, res => {
        res.on('data', buf => {
          // drain
        });
      });
    }));
  3. lpinca commented on Apr 30, 2019

    @lpinca
    Member

    I can't reproduce:

    $ dd if=/dev/urandom of=data.bin count=1024 bs=1024
    1024+0 records in
    1024+0 records out
    1048576 bytes transferred in 0.030293 secs (34614479 bytes/sec)
    
    $ cat finish.js 
    'use strict';
    
    const http = require('http');
    const { createReadStream } = require('fs');
    
    const server = http.createServer((req, res) => {
      createReadStream('./data.bin')
        .pipe(res)
        .on('finish', () => {
          console.log('finish');
        })
        .on('close', () => {
          console.log('close');
        });
    });
    
    server.listen(0, () => {
      http.get({ port: server.address().port }, (res) => {
        res.resume();
      });
    });
    
    $ node finish.js 
    finish
    close
    ^C
    
  4. added
    httpIssues and PRs related to the http subsystem.
    on Apr 30, 2019
  5. ronag commented on Apr 30, 2019

    @ronag
    MemberAuthor
    dd if=/dev/urandom of=data.bin count=1024 bs=1024
    1024+0 records in
    1024+0 records out
    1048576 bytes transferred in 0.029004 secs (36152686 bytes/sec)
    const http = require('http')
    const { createReadStream } = require('fs')
    
    const server = http
      .createServer((req, res) => {
        createReadStream('./data.bin')
          .pipe(res)
          .on('finish', () => console.log('finish'))
          .on('close', () => console.log('close'))
      })
    
    server.listen(9000, () => {
      http.get({ port: server.address().port }, res => {
        res.resume()
      })
    })
    storage$ node --version
    v10.13.0
    storage$ node tmp.js 
    finish
    ^C
  6. ronag commented on Apr 30, 2019

    @ronag
    MemberAuthor
    storage$ node --version && node tmp.js 
    v10.15.3
    finish
    ^C
  7. ronag commented on Apr 30, 2019

    @ronag
    MemberAuthor

    Works in node 11 and later. Not sure what commit fixed it?

    storage$ node --version && node tmp.js 
    v12.1.0
    finish
    close
    node --version && node tmp.js 
    v11.14.0
    finish
    close
  8. ronag commented on Apr 30, 2019

    @ronag
    MemberAuthor

    @mcollina is this something we want to fix in LTS or should I just drop it?

  9. lpinca commented on Apr 30, 2019

    @lpinca
    Member

    @ronag I think it is f22c7c1 (#20611) but it was reverted from v10.

  10. ronag commented on Apr 30, 2019

    @ronag
    MemberAuthor

    aah! yes, then it is as it should be

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues and 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