| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 61d1535 commit f7b53d0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -862,27 +862,12 @@ const requestChunkExtensionsTooLargeResponse = Buffer.from( | |||
| 862 | 862 | 'Connection: close\r\n\r\n', 'ascii', | |
| 863 | 863 | ); | |
| 864 | 864 | ||
| 865 | - function warnUnclosedSocket() { | ||
| 866 | - if (warnUnclosedSocket.emitted) { | ||
| 867 | - return; | ||
| 868 | - } | ||
| 869 | - | ||
| 870 | - warnUnclosedSocket.emitted = true; | ||
| 871 | - process.emitWarning( | ||
| 872 | - 'An error event has already been emitted on the socket. ' + | ||
| 873 | - 'Please use the destroy method on the socket while handling ' + | ||
| 874 | - "a 'clientError' event.", | ||
| 875 | - ); | ||
| 876 | - } | ||
| 877 | - | ||
| 878 | 865 | function socketOnError(e) { | |
| 879 | 866 | // Ignore further errors | |
| 880 | 867 | this.removeListener('error', socketOnError); | |
| 881 | 868 | ||
| 882 | 869 | if (this.listenerCount('error', noop) === 0) { | |
| 883 | 870 | this.on('error', noop); | |
| 884 | - } else { | ||
| 885 | - warnUnclosedSocket(); | ||
| 886 | 871 | } | |
| 887 | 872 | ||
| 888 | 873 | if (!this.server.emit('clientError', e, this)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,55 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + // Test that the `'clientError'` event can be emitted multiple times even if the | ||
| 5 | + // socket is correctly destroyed and that no warning is raised. | ||
| 6 | + | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const http = require('http'); | ||
| 9 | + const net = require('net'); | ||
| 10 | + | ||
| 11 | + process.on('warning', common.mustNotCall()); | ||
| 12 | + | ||
| 13 | + function socketListener(socket) { | ||
| 14 | + const firstByte = socket.read(1); | ||
| 15 | + if (firstByte === null) { | ||
| 16 | + socket.once('readable', () => { | ||
| 17 | + socketListener(socket); | ||
| 18 | + }); | ||
| 19 | + return; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + socket.unshift(firstByte); | ||
| 23 | + httpServer.emit('connection', socket); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + const netServer = net.createServer(socketListener); | ||
| 27 | + const httpServer = http.createServer(common.mustNotCall()); | ||
| 28 | + | ||
| 29 | + httpServer.once('clientError', common.mustCall((err, socket) => { | ||
| 30 | + assert.strictEqual(err.code, 'HPE_INVALID_METHOD'); | ||
| 31 | + assert.strictEqual(err.rawPacket.toString(), 'Q'); | ||
| 32 | + socket.destroy(); | ||
| 33 | + | ||
| 34 | + httpServer.once('clientError', common.mustCall((err) => { | ||
| 35 | + assert.strictEqual(err.code, 'HPE_INVALID_METHOD'); | ||
| 36 | + assert.strictEqual( | ||
| 37 | + err.rawPacket.toString(), | ||
| 38 | + 'WE http://example.com HTTP/1.1\r\n\r\n' | ||
| 39 | + ); | ||
| 40 | + })); | ||
| 41 | + })); | ||
| 42 | + | ||
| 43 | + netServer.listen(0, common.mustCall(() => { | ||
| 44 | + const socket = net.createConnection(netServer.address().port); | ||
| 45 | + | ||
| 46 | + socket.on('connect', common.mustCall(() => { | ||
| 47 | + socket.end('QWE http://example.com HTTP/1.1\r\n\r\n'); | ||
| 48 | + })); | ||
| 49 | + | ||
| 50 | + socket.on('close', () => { | ||
| 51 | + netServer.close(); | ||
| 52 | + }); | ||
| 53 | + | ||
| 54 | + socket.resume(); | ||
| 55 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,3 @@ | |||
| 1 | - // Flags: --no-warnings | ||
| 2 | - | ||
| 3 | 1 | 'use strict'; | |
| 4 | 2 | ||
| 5 | 3 | const common = require('../common'); | |
@@ -17,7 +15,7 @@ const net = require('net'); | |||
| 17 | 15 | { | |
| 18 | 16 | let i = 0; | |
| 19 | 17 | let socket; | |
| 20 | - process.on('warning', common.mustCall()); | ||
| 18 | + process.on('warning', common.mustNotCall()); | ||
| 21 | 19 | ||
| 22 | 20 | const server = http.createServer(common.mustNotCall()); | |
| 23 | 21 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments