forked from rase-/node-XMLHttpRequest
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle ECONNRESET possible on reused sockets (#19)
* Handle ECONNRESET possible on reused sockets If a request reuses a socket (due to an agent with keepalive), it's possible for the client to error with ECONNRESET. This error has nothing to do with the message being invalid, the server not responding, etc, but rather just very misfortunate timings. In this case, retry the request instead of erroring the xhr request * Update test for compatibility * Update test-utf8-tearing for early-node compatibility
- Loading branch information
Showing
4 changed files
with
62 additions
and
28 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
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,33 @@ | ||
var http = require('http'); | ||
var { XMLHttpRequest } = require("../lib/XMLHttpRequest"); | ||
|
||
var server = http.createServer({ keepAliveTimeout: 200 }, function handleConnection (req, res) { | ||
res.write('hello\n'); | ||
res.end(); | ||
}).listen(8889); | ||
|
||
var agent = new http.Agent({ | ||
keepAlive: true, | ||
keepAliveMsecs: 2000, | ||
}); | ||
var xhr = new XMLHttpRequest({ agent }); | ||
var url = "http://localhost:8889"; | ||
|
||
var repeats = 0; | ||
var maxMessages = 20; | ||
const interval = setInterval(function sendRequest() { | ||
xhr.open("GET", url); | ||
xhr.onloadend = function(event) { | ||
if (xhr.status !== 200) { | ||
console.error('Error: non-200 xhr response, message is\n', xhr.responseText); | ||
clearInterval(interval); | ||
server.close(); | ||
} | ||
if (repeats++ > maxMessages) { | ||
console.log('Done.'); | ||
clearInterval(interval); | ||
server.close(); | ||
} | ||
} | ||
xhr.send(); | ||
}, 200); |
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