diff --git a/deps/uv/src/win/tcp.c b/deps/uv/src/win/tcp.c index 0dcaa97df70821..f5ff14d0eb12dd 100644 --- a/deps/uv/src/win/tcp.c +++ b/deps/uv/src/win/tcp.c @@ -1429,11 +1429,7 @@ void uv_tcp_close(uv_loop_t* loop, uv_tcp_t* tcp) { if (tcp->flags & UV_HANDLE_READ_PENDING) { /* In order for winsock to do a graceful close there must not be any any * pending reads, or the socket must be shut down for writing */ - if (!(tcp->flags & UV_HANDLE_SHARED_TCP_SOCKET)) { - /* Just do shutdown on non-shared sockets, which ensures graceful close. */ - shutdown(tcp->socket, SD_SEND); - - } else if (uv_tcp_try_cancel_io(tcp) == 0) { + if (uv_tcp_try_cancel_io(tcp) == 0) { /* In case of a shared socket, we try to cancel all outstanding I/O,. If * that works, don't close the socket yet - wait for the read req to * return and close the socket in uv_tcp_endgame. */ diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index 0dfee0c9c7b619..1e3ba3a612c113 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -222,20 +222,6 @@ function onStreamRead(arrayBuffer) { if (stream[kMaybeDestroy]) stream.on('end', stream[kMaybeDestroy]); - // TODO(ronag): Without this `readStop`, `onStreamRead` - // will be called once more (i.e. after Readable.ended) - // on Windows causing a ECONNRESET, failing the - // test-https-truncate test. - if (handle.readStop) { - const err = handle.readStop(); - if (err) { - // CallJSOnreadMethod expects the return value to be a buffer. - // Ref: https://github.com/nodejs/node/pull/34375 - stream.destroy(errnoException(err, 'read')); - return; - } - } - // Push a null to signal the end of data. // Do it before `maybeDestroy` for correct order of events: // `end` -> `close` diff --git a/test/parallel/test-https-agent-jssocket-close.js b/test/parallel/test-https-agent-jssocket-close.js new file mode 100644 index 00000000000000..78c1076de3a3ab --- /dev/null +++ b/test/parallel/test-https-agent-jssocket-close.js @@ -0,0 +1,55 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const tls = require('tls'); +const fixtures = require('../common/fixtures'); +const https = require('https'); +const key = fixtures.readKey('agent1-key.pem'); +const cert = fixtures.readKey('agent1-cert.pem'); +const net = require('net'); +const { Duplex } = require('stream'); + +class CustomAgent extends https.Agent { + createConnection(options, cb) { + const realSocket = net.createConnection(options); + const stream = new Duplex({ + emitClose: false, + read(n) { + (function retry() { + const data = realSocket.read(); + if (data === null) + return realSocket.once('readable', retry); + stream.push(data); + })(); + }, + write(chunk, enc, callback) { + realSocket.write(chunk, enc, callback); + }, + }); + realSocket.on('end', () => stream.push(null)); + + stream.on('end', common.mustCall()); + return tls.connect({ ...options, socket: stream }); + } +} + +const httpsServer = https.createServer({ + key, + cert, +}, (req, res) => { + httpsServer.close(); + res.end('hello world!'); +}); +httpsServer.listen(0, 'localhost', () => { + const agent = new CustomAgent(); + https.get({ + host: 'localhost', + port: httpsServer.address().port, + agent, + headers: { Connection: 'close' }, + rejectUnauthorized: false + }, (res) => { + res.resume(); + }); +}); diff --git a/test/parallel/test-https-truncate.js b/test/parallel/test-https-truncate.js index beed36cd7c0819..a35ce8ba74d7a4 100644 --- a/test/parallel/test-https-truncate.js +++ b/test/parallel/test-https-truncate.js @@ -54,7 +54,6 @@ function httpsTest() { }); } - const test = common.mustCall(function(res) { res.on('end', common.mustCall(function() { assert.strictEqual(res.readableLength, 0);