From 6c90a7eb6f22be866f872b4a40e49c5238f619d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9licien=20FRANCOIS?= Date: Wed, 2 Mar 2016 15:41:05 +0100 Subject: [PATCH 1/5] Forward endpoint errors to httpsRequest Needed to be able to handles thoose errors gracefully because endpoint is not exposed. --- lib/http.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/http.js b/lib/http.js index 7c6d753f..c35ccd00 100644 --- a/lib/http.js +++ b/lib/http.js @@ -970,6 +970,7 @@ Agent.prototype.request = function request(options, callback) { endpoint = new Endpoint(self._log, 'CLIENT', self._settings); endpoint.socket = httpsRequest.socket; endpoint.pipe(endpoint.socket).pipe(endpoint); + endpoint.on('error', httpsRequest.emit.bind(httpsRequest, 'error')); } if (started) { // ** In the meantime, an other connection was made to the same host... From bd4a034e4901d86f576c5488ecb1934670848276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9licien=20FRANCOIS?= Date: Sun, 6 Mar 2016 13:46:12 +0100 Subject: [PATCH 2/5] Forward stream errors to request --- lib/http.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/http.js b/lib/http.js index c35ccd00..fe23fb01 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1059,6 +1059,8 @@ OutgoingRequest.prototype._start = function _start(stream, options) { this.stream = stream; this.options = options; + this.stream.on('error', this.emit.bind(this, 'error')); + this._log = stream._log.child({ component: 'http' }); for (var key in options.headers) { From 804477a6f91618825bff1bfa809bda97e7ff55a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9licien=20FRANCOIS?= Date: Sun, 6 Mar 2016 14:05:24 +0100 Subject: [PATCH 3/5] Forward stream errors to response --- lib/http.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/http.js b/lib/http.js index fe23fb01..8dc24077 100644 --- a/lib/http.js +++ b/lib/http.js @@ -703,6 +703,7 @@ function OutgoingResponse(stream) { this.statusCode = 200; this.sendDate = true; + this.stream.on('error', this.emit.bind(this, 'error')); this.stream.once('headers', this._onRequestHeaders.bind(this)); } OutgoingResponse.prototype = Object.create(OutgoingMessage.prototype, { constructor: { value: OutgoingResponse } }); From 19dfc70294d23fd745b4848b276bed175085cd42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9licien=20Fran=C3=A7ois?= Date: Sun, 6 Mar 2016 15:58:43 +0100 Subject: [PATCH 4/5] fix stream mocks --- test/http.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/http.js b/test/http.js index efd0f393..6dcf12a9 100644 --- a/test/http.js +++ b/test/http.js @@ -186,14 +186,14 @@ describe('http.js', function() { } else { called = true; } - }, once: util.noop }; + }, once: util.noop, on: util.noop }; var response = new http2.OutgoingResponse(stream); response.writeHead(200); response.writeHead(404); }); it('field finished should be Boolean', function(){ - var stream = { _log: util.log, headers: function () {}, once: util.noop }; + var stream = { _log: util.log, headers: function () {}, once: util.noop, on: util.noop }; var response = new http2.OutgoingResponse(stream); expect(response.finished).to.be.a('Boolean'); }); From 314cffdceae957d02c1f3383590c019808fd6f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9licien=20FRANCOIS?= Date: Sat, 23 Apr 2016 09:48:39 +0200 Subject: [PATCH 5/5] Add logging to stream and endpoint error forwarding --- lib/http.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/http.js b/lib/http.js index 8dc24077..bb66b72b 100644 --- a/lib/http.js +++ b/lib/http.js @@ -702,7 +702,11 @@ function OutgoingResponse(stream) { this.stream = stream; this.statusCode = 200; this.sendDate = true; - + var self = this; + this.stream.on('error', function (error) { + self._log.error('Stream error: ' + error.toString()); + self.emit('error', error); + }); this.stream.on('error', this.emit.bind(this, 'error')); this.stream.once('headers', this._onRequestHeaders.bind(this)); } @@ -971,7 +975,10 @@ Agent.prototype.request = function request(options, callback) { endpoint = new Endpoint(self._log, 'CLIENT', self._settings); endpoint.socket = httpsRequest.socket; endpoint.pipe(endpoint.socket).pipe(endpoint); - endpoint.on('error', httpsRequest.emit.bind(httpsRequest, 'error')); + endpoint.on('error', function (error) { + self._log.error('Endpoint error: ' + error.toString()); + httpsRequest.emit('error', error); + }); } if (started) { // ** In the meantime, an other connection was made to the same host... @@ -1060,9 +1067,13 @@ OutgoingRequest.prototype._start = function _start(stream, options) { this.stream = stream; this.options = options; - this.stream.on('error', this.emit.bind(this, 'error')); - this._log = stream._log.child({ component: 'http' }); + + var self = this; + stream.on('error', function (error) { + self._log.error('Stream error: ' + error.toString()); + self.emit('error', error); + }); for (var key in options.headers) { this.setHeader(key, options.headers[key]);