diff --git a/lib/_http_server.js b/lib/_http_server.js index bb9e65466873f1..3d114d87112e1b 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -363,8 +363,7 @@ function connectionListenerInternal(server, socket) { // Ensure that the server property of the socket is correctly set. // See https://github.com/nodejs/node/issues/13435 - if (socket.server === null) - socket.server = server; + socket.server = server; // If the user has added a listener to the server, // request, or response, then it's their responsibility. diff --git a/test/parallel/test-http-generic-streams.js b/test/parallel/test-http-generic-streams.js index aea371432a3d07..706cba7b385957 100644 --- a/test/parallel/test-http-generic-streams.js +++ b/test/parallel/test-http-generic-streams.js @@ -138,3 +138,17 @@ const MakeDuplexPair = require('../common/duplexpair'); req.write(testData); req.end(); } + +// Test 5: The client sends garbage. +{ + const server = http.createServer(common.mustNotCall()); + + const { clientSide, serverSide } = MakeDuplexPair(); + server.emit('connection', serverSide); + + server.on('clientError', common.mustCall()); + + // Send something that is not an HTTP request. + clientSide.end( + 'I’m reading a book about anti-gravity. It’s impossible to put down!'); +}