http_client: ensure empty socket on error
authorFedor Indutny <fedor@indutny.com>
Mon, 9 Mar 2015 00:30:01 +0000 (20:30 -0400)
committerFedor Indutny <fedor@indutny.com>
Mon, 9 Mar 2015 13:25:09 +0000 (09:25 -0400)
commit1a3ca8223e08d82051655d7d7e2ea31b439f1bf1
treee39089d810b0a15f85d69a040f8d0fb2d7494bf9
parent8670613d2d5dbfc191678caffe4c2bd228147046
http_client: ensure empty socket on error

Read all pending data out of the socket on `error` event and ensure that
no `data`/`end` handlers will be invoked on `socket.destroy()`.
Otherwise following assertion happens:

    AssertionError: null == true
        at TLSSocket.socketOnData (_http_client.js:308:3)
        at TLSSocket.emit (events.js:107:17)
        at TLSSocket.Readable.read (_stream_readable.js:373:10)
        at TLSSocket.socketCloseListener (_http_client.js:229:10)
        at TLSSocket.emit (events.js:129:20)
        at TCP.close (net.js:476:12)

Fix: https://github.com/joyent/node/issues/9348
PR-URL: https://github.com/iojs/io.js/pull/1103
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Nicu Micleușanu <micnic90@gmail.com>
lib/_http_client.js
test/parallel/test-http-client-read-in-error.js [new file with mode: 0644]