| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent df5dc2d commit 5d99a9b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,7 +346,6 @@ function socketCloseListener() { | |||
| 346 | 346 | // NOTE: It's important to get parser here, because it could be freed by | |
| 347 | 347 | // the `socketOnData`. | |
| 348 | 348 | var parser = socket.parser; | |
| 349 | - req.emit('close'); | ||
| 350 | 349 | if (req.res && req.res.readable) { | |
| 351 | 350 | // Socket closed before we emitted 'end' below. | |
| 352 | 351 | req.res.emit('aborted'); | |
@@ -362,6 +361,7 @@ function socketCloseListener() { | |||
| 362 | 361 | req.socket._hadError = true; | |
| 363 | 362 | req.emit('error', createHangUpError()); | |
| 364 | 363 | } | |
| 364 | + req.emit('close'); | ||
| 365 | 365 | ||
| 366 | 366 | // Too bad. That output wasn't getting written. | |
| 367 | 367 | // This is pretty terrible that it doesn't raise an error. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + // This test ensures that the `'close'` event is emitted after the `'error'` | ||
| 5 | + // event when a request is made and the socket is closed before we started to | ||
| 6 | + // receive a response. | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const http = require('http'); | ||
| 10 | + | ||
| 11 | + const server = http.createServer(common.mustNotCall()); | ||
| 12 | + | ||
| 13 | + server.listen(0, common.mustCall(() => { | ||
| 14 | + const req = http.get({ port: server.address().port }, common.mustNotCall()); | ||
| 15 | + let errorEmitted = false; | ||
| 16 | + | ||
| 17 | + req.on('error', (err) => { | ||
| 18 | + errorEmitted = true; | ||
| 19 | + assert.strictEqual(err.constructor, Error); | ||
| 20 | + assert.strictEqual(err.message, 'socket hang up'); | ||
| 21 | + assert.strictEqual(err.code, 'ECONNRESET'); | ||
| 22 | + }); | ||
| 23 | + | ||
| 24 | + req.on('close', common.mustCall(() => { | ||
| 25 | + assert.strictEqual(errorEmitted, true); | ||
| 26 | + server.close(); | ||
| 27 | + })); | ||
| 28 | + | ||
| 29 | + req.destroy(); | ||
| 30 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments