GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2stream.respondWithFile leaks a file descriptor every time statCheck returns false. · Issue #23029 · nodejs/node

http2stream.respondWithFile leaks a file descriptor every time statCheck returns false. #23029

New issue
Copy link
New issue
Copy link
Closed
#23047
Closed
http2stream.respondWithFile leaks a file descriptor every time statCheck returns false.#23029
#23047
Copy link
Labels
http2Issues and PRs related to the http2 subsystem.

Description

@aaronriekenberg
aaronriekenberg
opened on Sep 22, 2018
Issue body actions
  • Version: v10.11.0
  • Platform: Debian 9 stable: Linux 4.9.0-8-amd64 deps: update openssl to 1.0.1j #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) x86_64 GNU/Linux
  • Subsystem: http2

I am finding that when using http2stream.respondWithFile, if statCheck returns false to cancel the send based on stat data, the file descriptor opened for the stat call is leaked and is never closed.

Here is a simple example cut and pasted from the documentation (https://nodejs.org/api/http2.html#http2_http2stream_respondwithfile_path_headers_options):

#!/usr/bin/env node

'use strict';

const http2 = require('http2');

const server = http2.createServer();

server.on('stream', (stream) => {

  console.log('got stream');

  function statCheck(stat, headers) {
    console.log('in statCheck');
    stream.respond({ ':status': 304 });
    return false;
  }

  function onError(err) {
    if (err.code === 'ENOENT') {
      stream.respond({ ':status': 404 });
    } else {
      stream.respond({ ':status': 500 });
    }
    stream.end();
  }

  stream.respondWithFile('./somefile',
                         { 'content-type': 'text/plain' },
                         { statCheck, onError });
});

server.listen({ port: 8080 });
console.log('after server.listen');

Steps to reproduce:

  1. touch ./somefile
  2. Run code above in same directory as ./somefile
  3. curl --http2-prior-knowledge -v -k 'http://localhost:8080/'
  4. Look at /proc/${PID}/fd directory for node process. Observe for every curl a new fd is opened for ./somefile and is never closed. Observe that 'ls -l /proc/${PID}/fd | wc -l' increases by one for each curl call.

If the code above is modified to comment out the stream.respond and return false lines in statCheck, no file descriptors are leaked.

Looking at the code I think the issue is the fd is not closed when statCheck returns false in doSendFileFD because there is no call to tryClose(fd) here: https://github.com/nodejs/node/blob/v10.11.0/lib/internal/http2/core.js#L2094

This would be an easy DOS attack on any server using this pattern. If the client can make the server return 304 it can make the server run out of file descriptors and crash.

Activity

  1. aaronriekenberg
    closed this as completedon Sep 23, 2018
  2. aaronriekenberg
    reopened this on Sep 23, 2018
  3. jasnell
    added
    http2Issues and PRs related to the http2 subsystem.
    on Sep 23, 2018
  4. jasnell commented on Sep 23, 2018

    @jasnell
    jasnell
    on Sep 23, 2018
    Member
    More actions

    /cc @nodejs/http2 ... I'll be taking a look in the next day if someone doesn't beat me to it :-)

  5. cjihrig
    added a commit that references this issue on Sep 26, 2018

    http2: close fd in doSendFileFD()

    af5d986
  6. cjihrig
    closed this as completedin #23047on Sep 26, 2018
  7. targos
    added a commit that references this issue on Sep 27, 2018

    http2: close fd in doSendFileFD()

    d1826fe
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

    http2Issues and PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.