diff --git a/lib/eventsource.js b/lib/eventsource.js index 025941c..a81381d 100644 --- a/lib/eventsource.js +++ b/lib/eventsource.js @@ -242,6 +242,7 @@ function EventSource (url, eventSourceInitDict) { }) req.on('error', function (err) { + self.connectionInProgress = false onConnectionClosed(err.message) }) diff --git a/test/eventsource_test.js b/test/eventsource_test.js index 511bb0d..b0be4ec 100644 --- a/test/eventsource_test.js +++ b/test/eventsource_test.js @@ -710,6 +710,34 @@ describe('Reconnection', function () { } }) + it('continuing attempts when server is down', function (done) { + // Seems set reconnectInterval=0 not work here, this makes total time spent for current case more than 3S + this.timeout(4000) + + var es = new EventSource('http://localhost:' + _port++) + es.reconnectInterval = 0 + var reconnectCount = 0 + + es.onerror = function () { + reconnectCount++ + // make sure client is keeping reconnecting + if (reconnectCount > 2) { + es.onerror = null + var port = u.parse(es.url).port + configureServer(http.createServer(), 'http', port, function (err, server) { + if (err) return done(err) + + server.on('request', writeEvents(['data: hello\n\n'])) + + es.onmessage = function (m) { + assert.equal('hello', m.data) + server.close(done) + } + }) + } + } + }) + it('is attempted when server goes down after connection', function (done) { createServer(function (err, server) { if (err) return done(err)