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 — http/server: request.socket.bytesRead always 0 for IncomingMessage · Issue #3021 · nodejs/node

http/server: request.socket.bytesRead always 0 for IncomingMessage #3021

New issue
Copy link
New issue
Copy link
Closed
Closed
http/server: request.socket.bytesRead always 0 for IncomingMessage#3021
Copy link
Labels
confirmed-bugIssues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.netIssues and PRs related to the net subsystem.

Description

@skenqbx
skenqbx
opened on Sep 23, 2015
Issue body actions

Tested with node.js v4.1.0 & v4.1.1 (v0.10.x does not have this issue)

See the following test (parallel/test-http-bytesread.js) to reproduce the issue;

'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');

var body = 'hello world\n';
var sawEnd = false;
var bytesReadServer = 0;
var bytesReadClient = 0;

process.on('exit', function() {
  assert(sawEnd);
  console.log('ok');
});

var httpServer = http.createServer(function(req, res) {
  httpServer.close();

  req.on('readable', function() {
    var data = req.read();
    if (data !== null) {
      bytesReadServer += data.length;
    }
  });

  req.on('end', function() {
    assert(bytesReadServer > 0);
    assert(req.socket.bytesRead > 0);

    sawEnd = true;
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end(body);
  });
});

httpServer.listen(common.PORT, function() {
  var req = http.request({
    method: 'PUT',
    port: common.PORT
  }, function(res) {
    res.on('readable', function() {
      var data = res.read();
      if (data !== null) {
        bytesReadClient += data.length;
      }
    });

    res.on('end', function() {
      assert(bytesReadClient > 0);
      assert(res.socket.bytesRead > 0);
    });
  });

  var chunk = new Array(1024 + 1).join('7');
  var bchunk = new Buffer(chunk);

  for (var i = 0; i < 1024; i++) {
    req.write(chunk);
    req.write(bchunk);
    req.write(chunk, 'hex');
  }

  req.end();
});

I could not yet figure out what causes this, any help is appreciated.

Activity

  1. brendanashworth
    added
    httpIssues and PRs related to the http subsystem.
    on Sep 23, 2015
  2. not-implemented commented on Mar 7, 2016

    @not-implemented
    not-implemented
    on Mar 7, 2016
    Contributor
    More actions

    Same problem discovered here with node 4.3.1.

  3. raymondfeng commented on Mar 10, 2016

    @raymondfeng
    raymondfeng
    on Mar 10, 2016
    Contributor
    More actions

    @bnoordhuis Can you take a look? I need to use bytesRead/bytesWritten for analytics.

    Reacted by Jardel Weyrich
  4. jasnell
    added
    confirmed-bugIssues and PRs for confirmed bugs.
    on Apr 9, 2016
  5. jasnell commented on Apr 9, 2016

    @jasnell
    jasnell
    on Apr 9, 2016
    Member
    More actions

    ping @bnoordhuis @trevnorris ... a quick check on this indicates that in the test case above, it does not appear that the onread method in lib/net.js is being called for some as yet unknown reason. Because it is not called, the bytesRead is never incremented.

  6. jasnell
    added
    netIssues and PRs related to the net subsystem.
    on Apr 9, 2016
  7. bnoordhuis commented on Apr 9, 2016

    @bnoordhuis
    bnoordhuis
    on Apr 9, 2016
    Member
    More actions

    I think it's because of #2355 - the HTTP parser short-circuits the socket infrastructure in lib/net.js now. /cc @indutny.

  8. indutny commented on Apr 9, 2016

    @indutny
    indutny
    on Apr 9, 2016
    Member
    More actions

    @bnoordhuis exactly

  9. cjihrig commented on Apr 9, 2016

    @cjihrig
    cjihrig
    on Apr 9, 2016
    Contributor
    More actions

    If this is expected behavior, what are the next steps for this issue? Remove bytesRead? Fix it so that bytesRead works again?

  10. indutny commented on Apr 9, 2016

    @indutny
    indutny
    on Apr 9, 2016
    Member
    More actions

    @cjihrig I don't think that there is an efficient way to fix it... I'd rather vote for its removal. Probably need to discuss it on @nodejs/ctc call

  11. mscdex
    removed
    netIssues and PRs related to the net subsystem.
    on Apr 9, 2016
  12. Fishrock123
    added
    ctc-agenda
    on Apr 10, 2016
  13. mscdex
    added
    netIssues and PRs related to the net subsystem.
    on Apr 13, 2016
  14. mscdex commented on Apr 13, 2016

    @mscdex
    mscdex
    on Apr 13, 2016
    Contributor
    More actions

    @indutny What were some of the possible solutions you had in mind? @trevnorris said something about adding a data listener and manually incrementing the value from inside there. Does a simple fix like that impose a significant performance regression?

  15. indutny commented on Apr 13, 2016

    @indutny
    indutny
    on Apr 13, 2016
    Member
    More actions

    @mscdex I don't think I have any efficient solutions in mind. One is about making this property a getter for the case of consumed sockets and increment counter manually in C++.

  16. trevnorris commented on Apr 14, 2016

    @trevnorris
    trevnorris
    on Apr 14, 2016
    Contributor
    More actions

    The point about adding the data listener was only to illustrate that it could be fixed, but not that that is how it should be fixed.

    I personally like the idea of a getter. That has the lowest overhead for the common case of nit checking the property.

  17. indutny
    added a commit that references this issue on Apr 19, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit eb19df6 is merged into the 'v0.12' branch.
    eb19df6
  18. indutny commented on Apr 19, 2016

    @indutny
    indutny
    on Apr 19, 2016
    Member
    More actions

    Should be fixed by #6284

    Reacted by Malte
  19. indutny
    closed this as completedin 6198472on Apr 20, 2016
  20. jasnell
    removed
    ctc-agenda
    on Apr 20, 2016
  21. MylesBorins
    added 2 commits that reference this issue on Apr 20, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit 20dcdd3 is merged into the 'main' branch.
    20dcdd3

    stream_base: expose `bytesRead` getter

    This issue will close once commit 052d87c is merged into the 'main' branch.
    052d87c
  22. joelostrowski
    added a commit that references this issue on Apr 25, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit 4162dee is merged into the 'master' branch.
    4162dee
  23. jasnell
    added a commit that references this issue on Apr 26, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit 479344f is merged into the 'main' branch.
    479344f
  24. indutny
    added a commit that references this issue on May 20, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit f1c1355 is merged into the 'v0.12' branch.
    f1c1355
  25. MylesBorins
    added a commit that references this issue on Jun 1, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit b6c17a0 is merged into the 'main' branch.
    b6c17a0
  26. MylesBorins
    added 2 commits that reference this issue on Jun 23, 2016

    stream_base: expose `bytesRead` getter

    This issue will close once commit aee295b is merged into the 'main' branch.
    aee295b

    stream_base: expose `bytesRead` getter

    This issue will close once commit 55319fe is merged into the 'main' branch.
    55319fe
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

    confirmed-bugIssues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.netIssues and PRs related to the net 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.