Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait a macrotick to resume without pipelining
This change makes the Client wait for a full macrotick before executing up the next request if pipelining is disabled. This is to account for socket errors events that might be waiting to be processed in the event queue. This is the expected behavior without pipelining. This will slow us down a bit without pipelinig. Fixes: #1415 Signed-off-by: Matteo Collina <hello@matteocollina.com>
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const { fetch, request } = require('..') | ||
const http = require('http') | ||
|
||
const server = http.createServer((req, res) => { | ||
res.writeHead(200); | ||
res.end("Response body"); | ||
res.socket.end(); // Close the connection immediately with every response | ||
}).listen(0, '127.0.0.1', function () { | ||
const url = `http://127.0.0.1:${this.address().port}` | ||
request(url) | ||
.then(({ statusCode, headers, body }) => { | ||
t.pass('first response') | ||
body.resume() | ||
body.on('close', function () { | ||
t.pass('first body closed') | ||
}) | ||
return request(url) | ||
.then(({ statusCode, headers, body }) => { | ||
t.pass('second response') | ||
body.resume() | ||
body.on('close', function () { | ||
server.close() | ||
}) | ||
}) | ||
}).catch((err) => { | ||
t.error(err) | ||
}) | ||
}) |