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 #3021Labels confirmed-bugIssues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.netIssues and PRs related to the net subsystem. DescriptionTested 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. Activitynot-implemented commented on Mar 7, 2016 Same problem discovered here with node 4.3.1. raymondfeng commented on Mar 10, 2016 @bnoordhuis Can you take a look? I need to use bytesRead/bytesWritten for analytics. Reacted by Jardel Weyrich jasnell commented on Apr 9, 2016 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. bnoordhuis commented on Apr 9, 2016 I think it's because of #2355 - the HTTP parser short-circuits the socket infrastructure in lib/net.js now. /cc @indutny. indutny commented on Apr 9, 2016 cjihrig commented on Apr 9, 2016 If this is expected behavior, what are the next steps for this issue? Remove bytesRead? Fix it so that bytesRead works again? indutny commented on Apr 9, 2016 @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 mscdex commented on Apr 13, 2016 @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? indutny commented on Apr 13, 2016 @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++. trevnorris commented on Apr 14, 2016 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. added a commit that references this issue on Apr 19, 2016This issue will close once commit eb19df6 is merged into the 'v0.12' branch.eb19df6 indutny commented on Apr 19, 2016 added 2 commits that reference this issue on Apr 20, 2016This issue will close once commit 20dcdd3 is merged into the 'main' branch.20dcdd3 This issue will close once commit 052d87c is merged into the 'main' branch.052d87c added a commit that references this issue on Apr 25, 2016This issue will close once commit 4162dee is merged into the 'master' branch.4162dee added a commit that references this issue on Apr 26, 2016This issue will close once commit 479344f is merged into the 'main' branch.479344f added a commit that references this issue on May 20, 2016This issue will close once commit f1c1355 is merged into the 'v0.12' branch.f1c1355 added a commit that references this issue on Jun 1, 2016This issue will close once commit b6c17a0 is merged into the 'main' branch.b6c17a0 added 2 commits that reference this issue on Jun 23, 2016This issue will close once commit aee295b is merged into the 'main' branch.aee295b This issue will close once commit 55319fe is merged into the 'main' branch.55319fe
MetadataMetadataconfirmed-bugIssues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.netIssues and PRs related to the net subsystem. DevelopmentNo branches or pull requestsIssue actions
|