Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
test: test server response that waits for request end#29649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
mscdex commented Sep 22, 2019
Subsystem prefix in the commit message should be |
BridgeAR commented Sep 23, 2019
@nodejs/http PTAL |
Trott commented Sep 24, 2019
lpinca commented Sep 24, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
This needs investigation. I cannot reproduce with 'use strict';constassert=require('assert');consthttp=require('http');consttestData='Hello, World!\n';constserver=http.createServer(function(req,res){res.statusCode=200;res.setHeader('Content-Type','text/plain');res.end(testData);req.once('end',function(){res.end(testData);});});server.listen(8080,function(){constreq=http.request({port: 8080},function(res){res.setEncoding('utf8');letdata='';res.on('data',function(chunk){data+=chunk;});res.on('end',function(){assert.strictEqual(data,testData);server.close();});});req.end();});Works as expected. |
awwright commented Sep 24, 2019
@lpinca Your test 'use strict';constassert=require('assert');consthttp=require('http');consttestData='Hello, World!\n';constserver=http.createServer(function(req,res){res.statusCode=200;res.setHeader('Content-Type','text/plain');// res.end(testData);req.once('end',function(){res.end(testData);});});server.listen(8080,function(){constreq=http.request({port: 8080},function(res){res.setEncoding('utf8');letdata='';res.on('data',function(chunk){data+=chunk;});res.on('end',function(){assert.strictEqual(data,testData);server.close();});});req.end();}); |
awwright commented Sep 24, 2019
Actually, that's because the request was never resumed, ugh req.resume(); seems to make it work again The bug I'm looking to reproduce calls the request "end" event, but fails to write the ending to the response. |
awwright commented Sep 24, 2019
I'm going to spend some time better adapting #29609 |
awwright commented Sep 24, 2019
Added a chunked test case that passes, and a Content-Length test case that does not (but clearly should) |
awwright commented Sep 24, 2019
In chunked mode, Node.js works as expected (in all versions). In Content-Length mode, Node.js fails: Prior to 206ae31, Node.js failed only Starting 206ae31, Node.js fails both |
lpinca commented Sep 27, 2019
@awwright I copied your tests and again I can't reproduce with Detailsconstassert=require('assert');consthttp=require('http');consttestData='Hello, World!\n';{constserver=http.createServer(function(req,res){req.setEncoding('utf8');letdata='';req.on('data',function(chunk){data+=chunk;});req.on('end',function(){assert.strictEqual(data,testData);res.statusCode=200;res.setHeader('Content-Type','text/plain');res.write(testData);res.end();});});server.listen(function(){constreq=http.request({port: server.address().port,method: 'PUT',headers: {Connection: 'close'}},function(res){res.setEncoding('utf8');letdata='';res.on('data',function(chunk){data+=chunk;});res.on('end',function(){assert.strictEqual(data,testData);server.close();});});req.write(testData);req.end();});}{constlength=String(testData.length);constserver=http.createServer(function(req,res){assert.strictEqual(req.headers['content-length'],length);req.setEncoding('utf8');letdata='';req.on('data',function(chunk){data+=chunk;});req.once('end',function(){assert.strictEqual(data,testData);res.statusCode=200;res.setHeader('Content-Type','text/plain');res.setHeader('Content-Length',testData.length);res.write(testData);res.end();});});server.listen(function(){constreq=http.request({port: server.address().port,method: 'PUT',headers: {Connection: 'close','Content-Length': length}},function(res){assert.strictEqual(res.headers['content-length'],length);res.setEncoding('utf8');letdata='';res.on('data',function(chunk){data+=chunk;});res.on('end',function(){assert.strictEqual(data,testData);server.close();});});req.write(testData);req.end();});} |
awwright commented Sep 29, 2019
@lpinca I assume Nonetheless, is my assessment correct that this test should pass? |
lpinca commented Sep 29, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Yes, that's why in #29649 (comment) I said this needs investigation. |
Trott commented Oct 4, 2019
ronag commented Oct 4, 2019
awwright commented Oct 4, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@Trott I suppose #29649 (that seems to be included in #29836) would pass, but makeDuplexPair is also implemented in and at least a couple packages: https://yarnpkg.com/en/package/duplexpairhttps://yarnpkg.com/en/package/native-duplexpair (edit) Actually this would fix "tls", to whatever extent that's impacted |
awwright commented Oct 4, 2019
I didn't realize this was the test case I wrote up, let's try this again... #29836 is a decedent commit of this PR so it seems to cause the test to pass; but few other libraries still use the old code; e.g. https://yarnpkg.com/en/package/native-duplexpair; and it would need to be updated in the Writable documentation why I need to handle an empty write as a special case. Also, historical versions of my package would continue to fail, even though it was written for Node.js 12.0.0. Not the end of the world, but it makes e.g. |
ronag commented Oct 4, 2019
Updated PR with doc changes. Please take a look and see if you have any further suggestion. |
awwright commented Oct 4, 2019
@ronag It seems unintuitive to me, but with that explanation (that _read isn't really a callback, more like an event, so note a special case where it doesn't get called), I don't really have any reason to object. |
ronag commented Oct 4, 2019
@awwright: I didn't quite follow that :). If you make a commit or PR I'm more than happy to cherry pick your suggestion. |
If nothing is buffered then _read will not be called and the callback will not be invoked, effectivly deadlocking. Fixes: #29758 PR-URL: #29836 Refs: #29649 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
PR-URL: #29836 Refs: #29758 Refs: #29649 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
awwright commented Oct 8, 2019
Included in #29836 |
If nothing is buffered then _read will not be called and the callback will not be invoked, effectivly deadlocking. Fixes: #29758 PR-URL: #29836 Refs: #29649 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
PR-URL: #29836 Refs: #29758 Refs: #29649 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
This is a test that, by all indications, should pass, and would have passed prior to 206ae31
See #29609 for information.